rpm  5.4.15
libsql.c
Go to the documentation of this file.
1 #include "system.h"
2 
3 #define _RPMIOB_INTERNAL /* rpmiobSlurp */
4 #include <fts.h>
5 #include <mire.h>
6 #include <rpmdir.h>
7 #include <rpmmacro.h>
8 #include <rpmurl.h>
9 
10 #define _RPMSQL_INTERNAL
11 #define _RPMVT_INTERNAL
12 #define _RPMVC_INTERNAL
13 #include <rpmsql.h>
14 
15 #include <sqlite3.h>
16 
17 #include <rpmtypes.h>
18 #define _RPMTAG_INTERNAL
19 #include <rpmtag.h>
20 
21 #include <rpmts.h>
22 
23 #include <rpmgi.h>
24 
25 #include "debug.h"
26 
27 /*==============================================================*/
28 
29 typedef struct key_s {
30  const char * k;
31  uint32_t v;
32 } KEY;
33 static KEY sqlTypes[] = {
34  { "blob", SQLITE_BLOB },
35  { "float", SQLITE_FLOAT },
36  { "int", SQLITE_INTEGER },
37  { "integer",SQLITE_INTEGER },
38  { "null", SQLITE_NULL },
39  { "text", SQLITE_TEXT },
40 };
41 static size_t nsqlTypes = sizeof(sqlTypes) / sizeof(sqlTypes[0]);
42 
43 #ifdef REFERENCE
44 enum rpmTagType_e {
45  /* RPM_NULL_TYPE = 0 - never been used. */
46  /* RPM_CHAR_TYPE = 1 - never been used, same as RPM_UINT8_TYPE. */
47  RPM_UINT8_TYPE = 2,
48  RPM_UINT16_TYPE = 3,
49  RPM_UINT32_TYPE = 4,
50  RPM_UINT64_TYPE = 5,
51  RPM_STRING_TYPE = 6,
52  RPM_BIN_TYPE = 7,
55  /* RPM_ASN1_TYPE = 10 - never been used. */
56  /* RPM_OPENPGP_TYPE= 11 - never been used. */
57 };
58 #define RPM_MIN_TYPE 2
59 #define RPM_MAX_TYPE 9
60 #define RPM_MASK_TYPE 0x0000ffff
61 
62 static KEY tagTypes[] = {
63  { "", 0 },
64  { "char", RPM_UINT8_TYPE },
65  { "uint8", RPM_UINT8_TYPE },
66  { "uint16", RPM_UINT16_TYPE },
67  { "uint32", RPM_UINT32_TYPE },
68  { "uint64", RPM_UINT64_TYPE },
69  { "string", RPM_STRING_TYPE },
70  { "octets", RPM_BIN_TYPE },
71  { "argv", RPM_STRING_ARRAY_TYPE },
72  { "i18nstring", RPM_I18NSTRING_TYPE }
73 };
74 #endif /* REFERENCE */
75 
76 static KEY tagTypes[] = {
77  { "", 0 },
78  { "INTEGER", RPM_UINT8_TYPE },
79  { "INTEGER", RPM_UINT8_TYPE },
80  { "INTEGER", RPM_UINT16_TYPE },
81  { "INTEGER", RPM_UINT32_TYPE },
82  { "INTEGER", RPM_UINT64_TYPE },
83  { "TEXT", RPM_STRING_TYPE },
84  { "BLOB", RPM_BIN_TYPE },
85  { "TEXT", RPM_STRING_ARRAY_TYPE },
86  { "TEXT", RPM_I18NSTRING_TYPE },
87 };
88 #ifdef UNUSED
89 static size_t ntagTypes = sizeof(tagTypes) / sizeof(tagTypes[0]);
90 #endif
91 
92 static const char * hasSqlType(const char * s)
93 {
94  int i;
95  for (i = 0; i < (int)nsqlTypes; i++) {
96  const char * k = sqlTypes[i].k;
97  const char * se = strcasestr(s, k);
98  if (se == NULL || se <= s || se[-1] != ' ')
99  continue;
100  se += strlen(k);
101  if (*se && *se != ' ')
102  continue;
103  return se;
104  }
105  return NULL;
106 }
107 
108 /*==============================================================*/
109 static int _tag_debug;
110 
111 static char * tagJoin(const char * a, const char ** argv, const char * z)
112 {
113  static const char _type[] = " TEXT";
114  const char ** av;
115  size_t na = (sizeof("\t")-1) + (a ? strlen(a) : 0);
116  size_t nb = 0;
117  size_t nz = (z ? strlen(z) : 0) + strlen(_type) + (sizeof(",\n")-1);
118  char *t, *te;
119 
120  for (av = argv; *av != NULL; av++)
121  nb += na + strlen(*av) + nz;
122 
123  te = t = (char *) xmalloc(nb + 1);
124  for (av = argv; *av != NULL; av++) {
125  *te++ = '\t';
126  te = stpcpy(te, a);
127  te = stpcpy(te, *av);
128  if (hasSqlType(*av) == NULL)
129  te = stpcpy(te, _type);
130  te = stpcpy(te, z);
131  *te++ = ',';
132  *te++ = '\n';
133  }
134  *te = '\0';
135 
136  return t;
137 }
138 
139 static char * tagAppendCols(rpmvt vt, const char ** av)
140 {
141  char * h = tagJoin("", av, "");
142  int xx = argvAppend(&vt->cols, av);
143  char * u;
144  char * hu;
145 
146  /* XXX no selector so cols mapped from vt->argv[3] */
147  av = (const char **) (vt->argc > 3 ? &vt->argv[3] : vt->fields);
148 assert(av);
149  u = tagJoin("", av, "");
150  u[strlen(u)-2] = ' '; /* XXX nuke the final comma */
151  xx = argvAppend(&vt->cols, av);
152 
153 #define dbN vt->argv[1]
154 #define tblN vt->argv[2]
155  hu = rpmExpand("CREATE TABLE ", dbN, ".", tblN, " (\n", h, u, ");", NULL);
156 #undef dbN
157 #undef tblN
158 
159  u = _free(u);
160  h = _free(h);
161 
162 if (_tag_debug)
163 fprintf(stderr, "%s\n", hu);
164  return hu;
165 }
166 
167 static int tagLoadArgv(rpmvt vt, rpmvt * vtp)
168 {
169  sqlite3 * db = (sqlite3 *) vt->db;
170  rpmvd vd = vt->vd;
171 
172  const char * hu;
173 
174  int rc = SQLITE_OK;
175  int xx;
176 
177 SQLDBG((stderr, "--> %s(%p,%p)\n", __FUNCTION__, vt, vtp));
178 if (_tag_debug)
179 argvPrint("vt->argv", (ARGV_t)vt->argv, NULL);
180 
181  /* Set the columns in the schema. */
182  { static const char * _empty[] = { NULL };
183  hu = tagAppendCols(vt, _empty);
184  rc = rpmsqlCmd(NULL, "declare_vtab", db,
185  sqlite3_declare_vtab(db, hu));
186  hu = _free(hu);
187  }
188 
189  {
191  const struct headerTagTableEntry_s * tbl;
192 
193 #ifdef NOTYET
194  /* XXX this should use rpmHeaderFormats, but there are linkage problems. */
198  int extNum;
199 #endif
200 
201  for (tbl = _rpmTagTable; tbl && tbl->name; tbl++) {
202  const char * name = tbl->name + (sizeof("RPMTAG_")-1);
203  char tag[32];
204  uint32_t tx = (tbl->type & RPM_MASK_TYPE);
205  char attrs[32];
206  char * t;
207 
208  snprintf(tag, sizeof(tag), "%d", tbl->val);
209  snprintf(attrs, sizeof(attrs), "%d", (tbl->type >> 16));
210 assert(tx >= RPM_MIN_TYPE && tx <= RPM_MAX_TYPE);
211  t = rpmExpand(tag, vd->split, attrs, vd->split, tagTypes[tx].k,
212  vd->split, name, NULL);
213  xx = argvAdd(&vt->av, t);
214  t = _free(t);
215 
216  }
217 
218 #ifdef NOTYET
219  for (ext = exts, extNum = 0; ext != NULL && ext->type != HEADER_EXT_LAST;
220  ext = (ext->type == HEADER_EXT_MORE ? *ext->u.more : ext+1), extNum++)
221  {
222  if (ext->name == NULL || ext->type != HEADER_EXT_TAG)
223  continue;
224 
225  /* XXX don't print header tags twice. */
226  if (tagValue(ext->name) > 0)
227  continue;
228  fprintf(fp, "%s\n", ext->name + 7);
229  }
230 #endif
231 
232  }
233 
234  vt->ac = argvCount((ARGV_t)vt->av);
235 
236 if (_tag_debug)
237 argvPrint("vt->av", (ARGV_t)vt->av, NULL);
238 
239  if (vtp) {
240  if (!rc)
241  *vtp = (rpmvt) vt;
242  else {
243  *vtp = NULL;
244  (void) rpmvtFree(vt);
245  vt = NULL;
246  }
247  } else {
248  vt = rpmvtFree(vt);
249  vt = NULL;
250  }
251 
252 SQLDBG((stderr, "<-- %s(%p,%p) rc %d\n", __FUNCTION__, vt, vtp, rc));
253 
254  return rc;
255 }
256 
257 /*==============================================================*/
258 
259 static struct rpmvd_s _tagVD = {
260  .split = "|",
261  .parse = "tag integer primary key|attrs integer|type|name",
262 };
263 
264 static int tagCreate(void * _db, void * pAux,
265  int argc, const char *const * argv,
266  rpmvt * vtp, char ** pzErr)
267 {
268  return tagLoadArgv(rpmvtNew(_db, pAux, argv, &_tagVD), vtp);
269 }
270 
271 struct sqlite3_module tagModule = {
272  .iVersion = 0,
273  .xCreate = (void *) tagCreate,
274  .xConnect = (void *) tagCreate,
275 };
276 
277 /*==============================================================*/
278 static int _xxx_debug = 0;
279 
280 static char * _rpmvtJoin(const char * a, const char ** argv, const char * z)
281 {
282  static const char _type[] = " TEXT";
283  const char ** av;
284  size_t na = (sizeof("\t")-1) + (a ? strlen(a) : 0);
285  size_t nb = 0;
286  size_t nz = (z ? strlen(z) : 0) + strlen(_type) + (sizeof(",\n")-1);
287  char *t, *te;
288 
289  for (av = argv; *av != NULL; av++)
290  nb += na + strlen(*av) + nz;
291 
292  te = t = (char *) xmalloc(nb + 1);
293  for (av = argv; *av != NULL; av++) {
294  *te++ = '\t';
295  te = stpcpy(te, a);
296  te = stpcpy(te, *av);
297  if (hasSqlType(*av) == NULL)
298  te = stpcpy(te, _type);
299  te = stpcpy(te, z);
300  *te++ = ',';
301  *te++ = '\n';
302  }
303  *te = '\0';
304 
305  return t;
306 }
307 
308 static char * _rpmvtAppendCols(rpmvt vt, const char ** av)
309 {
310  char * h = _rpmvtJoin("", av, "");
311  int xx = argvAppend(&vt->cols, av);
312  char * u;
313  char * hu;
314 
315  av = (const char **) (vt->argc > 4 ? &vt->argv[4] : vt->fields);
316 assert(av);
317  u = _rpmvtJoin("", av, "");
318  u[strlen(u)-2] = ' '; /* XXX nuke the final comma */
319  xx = argvAppend(&vt->cols, av);
320 
321 #define dbN vt->argv[1]
322 #define tblN vt->argv[2]
323  hu = rpmExpand("CREATE TABLE ", dbN, ".", tblN, " (\n", h, u, ");", NULL);
324 #undef dbN
325 #undef tblN
326 
327  u = _free(u);
328  h = _free(h);
329 
330 if (_xxx_debug)
331 fprintf(stderr, "%s\n", hu);
332  return hu;
333 }
334 
335 static int _rpmvtLoadArgv(rpmvt vt, rpmvt * vtp)
336 {
337  sqlite3 * db = (sqlite3 *) vt->db;
338  rpmvd vd = vt->vd;
339 
340  static const char * hidden[] = { "path HIDDEN", "id HIDDEN", NULL };
341  const char * hu;
342 
343  char * uri = NULL;
344  struct stat sb;
345 
346  const char * fn = NULL;
347 
348  int rc = SQLITE_OK;
349  int xx;
350  int i;
351 
352 if (_xxx_debug)
353 fprintf(stderr, "--> %s(%p,%p)\n", __FUNCTION__, vt, vtp);
354 if (_xxx_debug)
355 argvPrint("vt->argv", (ARGV_t)vt->argv, NULL);
356 
357  /* Set the columns in the schema. */
358  hu = _rpmvtAppendCols(vt, hidden);
359  rc = rpmsqlCmd(NULL, "declare_vtab", db,
360  sqlite3_declare_vtab(db, hu));
361  hu = _free(hu);
362 
363  if (vt->argv[3]) {
364  /* XXX slice out the quotes that sqlite passes through ... */
365  static char _quotes[] = "'\"";
366  int quoted = (strchr(_quotes, *vt->argv[3]) != NULL);
367  const char * prefix;
368  const char * path = NULL;
369  /* XXX Prefer user override to global prefix (if absolute path). */
370  (void) urlPath(vt->argv[3]+quoted, &path);
371  prefix = (*path != '/' && vd->prefix ? vd->prefix : "");
372  uri = rpmGetPath(prefix, path, NULL);
373  uri[strlen(uri)-quoted] = '\0';
374  } else
375  uri = rpmGetPath(vd->prefix, fn, NULL);
376 
377  (void) urlPath(uri, (const char **) &fn);
378 
379  if (!strcasecmp(vt->argv[0], "nixdb")) {
380  const char * out = rpmExpand("%{sql ", vd->dbpath, ":",
381  "select path from ValidPaths where glob('", fn, "', path);",
382  "}", NULL);
383  (void) argvSplit(&vt->av, out, "\n");
384  out = _free(out);
385  } else
386 
387  if (fn[0] == '/') {
388 if (_xxx_debug)
389 fprintf(stderr, "*** uri %s fn %s\n", uri, fn);
390  if (Glob_pattern_p(uri, 0)) { /* XXX uri */
391  const char ** av = NULL;
392  int ac = 0;
393 
394  xx = rpmGlob(uri, &ac, &av); /* XXX uri */
395 if (_xxx_debug)
396 fprintf(stderr, "GLOB: %d = Glob(%s) av %p[%d]\n", xx, uri, av, ac);
397  if (xx)
398  rc = SQLITE_NOTFOUND; /* XXX */
399  else
400  xx = argvAppend(&vt->av, (ARGV_t)av);
401  av = argvFree(av);
402  } else
403  if (uri[strlen(uri)-1] == '/') {
404  DIR * dir = Opendir(uri);
405  struct dirent * dp;
406 if (_xxx_debug)
407 fprintf(stderr, " DIR: %p = Opendir(%s)\n", dir, uri);
408  if (dir == NULL)
409  rc = SQLITE_NOTFOUND; /* XXX */
410  else
411  while ((dp = Readdir(dir)) != NULL) {
412  if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
413  continue;
414  fn = rpmGetPath(uri, "/", dp->d_name, NULL);
415  xx = argvAdd(&vt->av, fn);
416  fn = _free(fn);
417  }
418  if (dir) xx = Closedir(dir);
419  } else
420  if (!Lstat(uri, &sb)) {
421  rpmiob iob = NULL;
422  xx = rpmiobSlurp(uri, &iob);
423 if (_xxx_debug)
424 fprintf(stderr, "FILE: %d = Slurp(%s)\n", xx, uri);
425  if (!xx)
426  xx = argvSplit(&vt->av, rpmiobStr(iob), "\n");
427  else
428  rc = SQLITE_NOTFOUND; /* XXX */
429  iob = rpmiobFree(iob);
430  } else
431  rc = SQLITE_NOTFOUND; /* XXX */
432  } else
433  if (!strcasecmp(vt->argv[0], "Env")) {
434 if (_xxx_debug)
435 fprintf(stderr, " ENV: getenv(%p[%d])\n", &vt->argv[3], argvCount(&vt->argv[3]));
436  for (i = 3; i < vt->argc; i++) {
437  char * t = rpmExpand(vt->argv[i], "=", getenv(vt->argv[i]), NULL);
438  xx = argvAdd(&vt->av, t);
439  t = _free(t);
440  }
441  } else {
442  xx = argvAppend(&vt->av, (ARGV_t)&vt->argv[3]);
443 if (_xxx_debug)
444 fprintf(stderr, "LIST: %d = Append(%p[%d])\n", xx, &vt->argv[3], argvCount(&vt->argv[3]));
445  }
446 
447  vt->ac = argvCount((ARGV_t)vt->av);
448 
449  uri = _free(uri);
450 
451 if (_xxx_debug)
452 argvPrint("vt->av", (ARGV_t)vt->av, NULL);
453 
454  if (vtp) {
455  if (!rc)
456  *vtp = (rpmvt) vt;
457  else {
458  *vtp = NULL;
459  (void) rpmvtFree(vt);
460  vt = NULL;
461  }
462  } else {
463  vt = rpmvtFree(vt);
464  vt = NULL;
465  }
466 
467 if (_xxx_debug)
468 fprintf(stderr, "<-- %s(%p,%p) rc %d\n", __FUNCTION__, vt, vtp, rc);
469 
470  return rc;
471 }
472 
473 /*==============================================================*/
474 static int hdrColumn(rpmvc vc, void * _pContext, int colx)
475 {
476  sqlite3_context * pContext = (sqlite3_context *) _pContext;
477  rpmvt vt = vc->vt;
478  const char * path = vt->av[vc->ix];
479  const char * col = vt->cols[colx];
480 
481  int xx;
482 
483  int rc = SQLITE_OK;
484 
485 if (_xxx_debug < 0)
486 fprintf(stderr, "--> %s(%p,%p,%d)\n", __FUNCTION__, vc, pContext, colx);
487 
488  if (!strcmp(col, "path"))
489  sqlite3_result_text(pContext, path, -1, SQLITE_STATIC);
490 
491  else {
492  HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
493  Header h = (Header) vt->_h;
494 
495 assert(h);
496  he->tag = tagValue(col);
497  if ((xx = headerGet(h, he, 0)) == 0)
498  sqlite3_result_null(pContext);
499  else {
500 if (_xxx_debug)
501 fprintf(stderr, "*** tag %u t %u p.ptr %p c %u\n", he->tag, he->t, he->p.ptr, he->c);
502  switch (he->t) {
503  default:
504  case RPM_UINT8_TYPE:
505  sqlite3_result_int(pContext, he->p.ui8p[0]);
506  break;
507  case RPM_UINT16_TYPE:
508  sqlite3_result_int(pContext, he->p.ui16p[0]);
509  break;
510  case RPM_UINT32_TYPE:
511  sqlite3_result_int(pContext, he->p.ui32p[0]);
512  break;
513  case RPM_UINT64_TYPE:
514  sqlite3_result_int64(pContext, he->p.ui64p[0]);
515  break;
516  case RPM_BIN_TYPE:
517  sqlite3_result_blob(pContext, he->p.ptr, he->c, SQLITE_TRANSIENT);
518  break;
519  case RPM_I18NSTRING_TYPE:
520 #if !defined(SUPPORT_I18NSTRING_TYPE)
521 assert(0);
522 #endif
523  case RPM_STRING_TYPE:
524  sqlite3_result_text(pContext, he->p.str, -1, SQLITE_TRANSIENT);
525  break;
527  sqlite3_result_text(pContext, he->p.argv[0], -1, SQLITE_TRANSIENT);
528  break;
529  }
530  }
531  he->p.ptr = _free(he->p.ptr);
532  }
533 
534 if (_xxx_debug < 0)
535 fprintf(stderr, "<-- %s(%p,%p,%d) rc %d\n", __FUNCTION__, vc, pContext, colx, rc);
536 
537  return rc;
538 }
539 
540 /*==============================================================*/
541 static int hdrLoadNext(rpmvc vc)
542 {
543  rpmvt vt = vc->vt;
544  rpmgi gi = (rpmgi) vt->_gi;
545  Header h = (Header) vt->_h;
546  rpmRC rc;
547 
548  if (h) {
549  (void) headerFree(h);
550  h = NULL;
551  vt->_h = h;
552  }
553 
554  if (vc->ix >= 0 && vc->ix < vc->nrows) {
555  rc = rpmgiNext(gi);
556  h = rpmgiHeader(gi);
557  vt->_h = headerLink(h);
558  } else
559  rc = RPMRC_NOTFOUND;
560 
561  return rc;
562 }
563 
564 /*==============================================================*/
565 
566 static int hdrFilter(rpmvc vc, int idxNum, const char * idxStr,
567  int argc, rpmvArg * _argv)
568 {
569  sqlite3_value ** argv = (sqlite3_value **) _argv;
570  int rc = SQLITE_OK;
571 
572 if (_xxx_debug)
573 fprintf(stderr, "--> %s(%p,%d,%s,%p[%u]) [%d:%d]\n", __FUNCTION__, vc, idxNum, idxStr, argv, (unsigned)argc, vc->ix, vc->nrows);
574 
575  if (vc->nrows > 0) {
576  vc->ix = 0;
577  if (hdrLoadNext(vc)) rc = SQLITE_NOTFOUND; /* XXX */
578  }
579 
580 if (_xxx_debug)
581 fprintf(stderr, "<-- %s(%p,%d,%s,%p[%u]) [%d:%d] rc %d\n", __FUNCTION__, vc, idxNum, idxStr, argv, (unsigned)argc, vc->ix, vc->nrows, rc);
582 
583  return rc;
584 }
585 
586 static int hdrNext(rpmvc vc)
587 {
588  int rc = SQLITE_OK;
589 
590  if (vc->ix >= 0 && vc->ix < vc->nrows) { /* XXX needed? */
591  vc->ix++;
592  if (hdrLoadNext(vc)) rc = SQLITE_NOTFOUND; /* XXX */
593 rc = 0;
594  }
595 
596 if (!(vc->ix >= 0 && vc->ix < vc->nrows))
597 if (_xxx_debug)
598 fprintf(stderr, "<-- %s(%p) [%d:%d] rc %d\n", __FUNCTION__, vc, vc->ix, vc->nrows, rc);
599  return rc;
600 }
601 
602 static int hdrEof(rpmvc vc)
603 {
604 rpmvt vt = vc->vt;
605  int rc = (vc->ix >= 0 && vc->ix < vc->nrows ? 0 : 1);
606 
607 if (_xxx_debug)
608 fprintf(stderr, "<-- %s(%p) h %p rc %d\n", __FUNCTION__, vc, vt->_h, rc);
609  return rc;
610 }
611 
612 /*==============================================================*/
613 
614 static struct rpmvd_s _hdrVD = {
615  /* XXX where to map the default? */
616  .prefix = "%{?_repodb}%{!?_repodb:/X/popt/}",
617  .split = "/|",
618  .parse = "Name|Epoch integer|Version|Release|Arch|Os|Providename|Provideversion|Provideflags|Sigmd5 blob|Nvra|Summary",
619 };
620 
621 static int hdrCreate(void * _db, void * pAux,
622  int argc, const char *const * argv,
623  rpmvt * vtp, char ** pzErr)
624 {
625  int rc = _rpmvtLoadArgv(rpmvtNew(_db, pAux, argv, &_hdrVD), vtp);
626 
627  if (!rc && vtp) {
628  rpmvt vt = *vtp;
629  rpmts _ts = rpmtsCreate();
630  int _tag = RPMDBI_ARGLIST;
631  rpmgi _gi = rpmgiNew(_ts, _tag, NULL, 0);
632  int _FtsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);
633  int _giFlags = RPMGI_NONE;
634  rpmRC rc = rpmgiSetArgs(_gi, vt->av, _FtsOpts, _giFlags);
635 rc = rc;
636  vt->_ts = _ts;
637  vt->_gi = _gi;
638  }
639  return rc;
640 }
641 
642 static int hdrDestroy(rpmvt vt)
643 {
644  vt->_h = headerFree(vt->_h);
645  vt->_gi = rpmgiFree(vt->_gi);
646  vt->_ts = rpmtsFree(vt->_ts);
647  (void) rpmvtFree(vt);
648  return 0; /* SQLITE_OK */
649 }
650 
651 
652 struct sqlite3_module hdrModule = {
653  .iVersion = 0,
654  .xCreate = (void *) hdrCreate,
655  .xConnect = (void *) hdrCreate,
656  .xColumn = (void *) hdrColumn,
657  .xFilter = (void *) hdrFilter,
658  .xNext = (void *) hdrNext,
659  .xEof = (void *) hdrEof,
660  .xDisconnect= (void *) hdrDestroy,
661  .xDestroy = (void *) hdrDestroy,
662 };
663 
664 /*==============================================================*/
665 
666 static struct rpmsqlVMT_s __VMT[] = {
667  { "Rpmtags", &tagModule, NULL },
668  { "Header", &hdrModule, NULL },
669  { NULL, NULL, NULL }
670 };
671 
672 extern int sqlite3_extension_init(void * _db);
673 int sqlite3_extension_init(void * _db)
674 {
675  int rc = 0; /* SQLITE_OK */
676 fprintf(stderr, "--> %s(%p)\n", __FUNCTION__, _db);
677  rc = _rpmsqlLoadVMT(_db, __VMT);
678 fprintf(stderr, "<-- %s(%p) rc %d\n", __FUNCTION__, _db, rc);
679  return rc;
680 }
rpmTagType t
Definition: rpmtag.h:504
static KEY sqlTypes[]
Definition: libsql.c:33
const char * str
Definition: rpmtag.h:73
rpmTag tag
Definition: rpmtag.h:503
const char ** argv
Definition: rpmtag.h:75
headerTagTableEntry rpmTagTable
Automatically generated table of tag name/value pairs.
Definition: tagtbl.c:239
#define RPM_MAX_TYPE
Definition: rpmtag.h:42
char * getenv(const char *name)
rpmuint32_t * ui32p
Definition: rpmtag.h:70
Definition: libsql.c:29
rpmgi rpmgiFree(rpmgi gi)
Destroy a generalized iterator.
static char * _rpmvtAppendCols(rpmvt vt, const char **av)
Definition: libsql.c:308
char * rpmGetPath(const char *path,...)
Return (malloc'ed) expanded, canonicalized, file path.
Definition: macro.c:3445
static int hdrFilter(rpmvc vc, int idxNum, const char *idxStr, int argc, rpmvArg *_argv)
Definition: libsql.c:566
struct sqlite3_module hdrModule
Definition: libsql.c:652
struct headerToken_s * Header
Definition: rpmtag.h:22
int headerGet(Header h, HE_t he, unsigned int flags)
Retrieve extension or tag value from a header.
Definition: header.c:2231
The Header data structure.
static int tagCreate(void *_db, void *pAux, int argc, const char *const *argv, rpmvt *vtp, char **pzErr)
Definition: libsql.c:264
int argvAppend(ARGV_t *argvp, ARGV_t av)
Append one argv array to another.
Definition: argv.c:216
rpmuint16_t * ui16p
Definition: rpmtag.h:69
int rpmsqlCmd(rpmsql sql, const char *msg, void *_db, int rc)
Check sqlite3 return code, displaying error messages.
Header rpmgiHeader(rpmgi gi)
Return current iteration header.
Definition: rpmgi.c:847
struct rpmvd_s * rpmvd
Definition: rpmsql.h:16
static struct rpmsqlVMT_s __VMT[]
Definition: libsql.c:666
static struct headerSprintfExtension_s _rpmHeaderFormats[]
Definition: formats.c:274
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
#define tblN
static int hdrNext(rpmvc vc)
Definition: libsql.c:586
#define dbN
static struct rpmvd_s _hdrVD
Definition: libsql.c:614
rpmTag tagValue(const char *tagstr)
Return tag value from name.
Definition: tagname.c:446
int rpmiobSlurp(const char *fn, rpmiob *iobp)
Definition: rpmiob.c:129
char * alloca()
int sqlite3_extension_init(void *_db)
Definition: libsql.c:673
rpmTagType_e
The basic types of data in tags from headers.
Definition: rpmtag.h:27
int rpmGlob(const char *patterns, int *argcPtr, const char ***argvPtr)
Return URL path(s) from a (URL prefixed) pattern glob.
Definition: macro.c:2611
struct _HE_s * HE_t
Definition: rpmtag.h:59
static size_t ntagTypes
Definition: sqlite.c:892
void * ptr
Definition: rpmtag.h:67
rpmgi rpmgiNew(rpmts ts, int tag, const void *keyp, size_t keylen)
Return a generalized iterator.
Definition: rpmgi.c:543
struct rpmvt_s * rpmvt
Definition: rpmsql.h:19
rpmvt rpmvtNew(void *db, void *pModule, const char *const *argv, rpmvd vd)
Definition: rpmsql.c:108
RPM pattern matching.
int argvCount(const ARGV_t argv)
Return no.
Definition: argv.c:71
#define FTS_COMFOLLOW
Definition: fts.h:87
int Lstat(const char *path, struct stat *st)
lstat(2) clone.
Definition: rpmrpc.c:1401
rpmTagData p
Definition: rpmtag.h:506
static const struct headerTagTableEntry_s _rpmTagTable[]
Definition: tagtbl.c:9
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
Definition: argv.c:44
uint32_t v
Definition: libsql.c:31
int Glob_pattern_p(const char *pattern, int quote)
glob_pattern_p(3) clone.
Definition: rpmrpc.c:2231
rpmRC rpmgiSetArgs(rpmgi gi, ARGV_t argv, int ftsOpts, rpmgiFlags flags)
Load iterator args.
Definition: rpmgi.c:866
int argvAdd(ARGV_t *argvp, ARGstr_t val)
Add a string to an argv array.
Definition: argv.c:199
const struct headerSprintfExtension_s * headerSprintfExtension
Definition: rpmtag.h:134
rpmTagCount c
Definition: rpmtag.h:507
Header headerFree(Header h)
Dereference a header instance.
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
Definition: macro.c:3252
static int hdrLoadNext(rpmvc vc)
Definition: libsql.c:541
#define dirent
Definition: system.h:245
rpmuint8_t * ui8p
Definition: rpmtag.h:68
void argvPrint(const char *msg, ARGV_t argv, FILE *fp)
Print argv array elements.
Definition: argv.c:19
#define RPM_MIN_TYPE
Definition: rpmtag.h:41
static int hdrCreate(void *_db, void *pAux, int argc, const char *const *argv, rpmvt *vtp, char **pzErr)
Definition: libsql.c:621
Header headerLink(Header h)
Reference a header instance.
static int _rpmvtLoadArgv(rpmvt vt, rpmvt *vtp)
Definition: libsql.c:335
struct rpmgi_s * rpmgi
Generalized iterator.
Definition: rpmtypes.h:53
enum rpmRC_e rpmRC
RPM return codes.
#define RPMDBI_ARGLIST
Definition: rpmtag.h:486
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
Definition: rpmiob.c:112
Definition: rpmtag.h:502
static const char * hasSqlType(const char *s)
Definition: libsql.c:92
const char const int i
Definition: bson.h:778
static int tagLoadArgv(rpmvt vt, rpmvt *vtp)
Definition: libsql.c:167
urltype urlPath(const char *url, const char **pathp)
Return path component of URL.
Definition: url.c:430
static int snprintf(char *buf, int nb, const char *fmt,...)
Definition: rpmps.c:220
static const char * prefix[]
Tables for prefixing and suffixing patterns, according to the -w, -x, and -F options.
Definition: rpmgrep.c:183
const char const bson const bson bson * out
Definition: mongo.h:678
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
struct dirent * Readdir(DIR *dir)
readdir(3) clone.
Definition: rpmdir.c:432
rpmts rpmtsCreate(void)
Create an empty transaction set.
Definition: rpmts.c:1470
static KEY tagTypes[]
Definition: libsql.c:76
static char * _rpmvtJoin(const char *a, const char **argv, const char *z)
Definition: libsql.c:280
char * stpcpy(char *dest, const char *src)
struct rpmts_s * rpmts
The RPM Transaction Set.
Definition: rpmtypes.h:14
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:756
struct rpmiob_s * rpmiob
Definition: rpmiotypes.h:60
static int _tag_debug
Definition: libsql.c:109
Structures and prototypes used for an "rpmts" transaction set.
const char * db
Definition: mongo.h:697
const struct headerTagTableEntry_s * headerTagTableEntry
Definition: rpmtag.h:525
static struct rpmvd_s _tagVD
Definition: libsql.c:259
int argvSplit(ARGV_t *argvp, const char *str, const char *seps)
Split a string into an argv array.
Definition: argv.c:233
#define FTS_LOGICAL
Definition: fts.h:88
static int hdrEof(rpmvc vc)
Definition: libsql.c:602
rpmRC rpmgiNext(rpmgi gi)
Perform next iteration step.
Definition: rpmgi.c:584
int Closedir(DIR *dir)
closedir(3) clone.
Definition: rpmdir.c:385
#define RPM_MASK_TYPE
Definition: rpmtag.h:43
static const char * name
static int hdrDestroy(rpmvt vt)
Definition: libsql.c:642
#define xmalloc
Definition: system.h:32
struct key_s KEY
DIR * Opendir(const char *path)
opendir(3) clone.
Definition: rpmdir.c:396
static char * tagJoin(const char *a, const char **argv, const char *z)
Definition: libsql.c:111
static int _xxx_debug
Definition: libsql.c:278
static int hdrColumn(rpmvc vc, void *_pContext, int colx)
Definition: libsql.c:474
ARGstr_t * ARGV_t
Definition: argv.h:12
#define FTS_NOSTAT
Definition: fts.h:90
void * rpmvArg
Definition: rpmsql.h:14
static char * tagAppendCols(rpmvt vt, const char **av)
Definition: libsql.c:139
struct rpmvc_s * rpmvc
Definition: rpmsql.h:18
static size_t nsqlTypes
Definition: libsql.c:41
struct sqlite3_module tagModule
Definition: libsql.c:271
headerSprintfExtension headerCompoundFormats
Supported default header extension/tag output formats.
Definition: hdrfmt.c:5278
rpmuint64_t * ui64p
Definition: rpmtag.h:71
const char * k
Definition: libsql.c:30