rpm  5.4.14
rpmmi-rb.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #include "rpm-rb.h"
8 #include "rpmts-rb.h"
9 #include "rpmmi-rb.h"
10 #include "rpmhdr-rb.h"
11 
12 #ifdef NOTYET
13 #include <argv.h>
14 #endif
15 #include <mire.h>
16 
17 #include <rpmdb.h>
18 #include <rpmts.h>
19 #include <rpmio.h>
20 
21 #include "../debug.h"
22 
23 VALUE rpmmiClass;
24 
25 /*@unchecked@*/
26 static int _debug = 0;
27 
28 /* --- helpers */
29 static void *
30 rpmmi_ptr(VALUE s)
31 {
32  void *ptr;
33  Data_Get_Struct(s, void, ptr);
34  return ptr;
35 }
36 
37 /* --- Object methods */
38 static VALUE
39 rpmmi_each(VALUE s)
40 {
41  rpmmi mi = rpmmi_ptr(s);
42  Header h;
43  while((h = rpmmiNext(mi)) != NULL)
44  rb_yield (rpmrb_NewHdr(headerLink(h)));
45  return Qnil;
46 }
47 
48 static VALUE
49 rpmmi_next(VALUE s)
50 {
51  rpmmi mi = rpmmi_ptr(s);
52  Header h = rpmmiNext(mi);
53  return (h != NULL ? rpmrb_NewHdr(headerLink(h)) : Qnil);
54 }
55 
56 static VALUE
57 rpmmi_pattern(int argc, VALUE *argv, VALUE s)
58 {
59  rpmmi mi = rpmmi_ptr(s);
60  VALUE v_tag, v_pattern;
61 
62  rb_scan_args(argc, argv, "20", &v_tag, &v_pattern);
63 
64  rpmmiAddPattern(mi, FIX2INT(v_tag), RPMMIRE_REGEX,
65  StringValueCStr(v_pattern));
66 
67  return Qtrue;
68 }
69 
70 static void
71 initMethods(VALUE klass)
72 {
73  rb_define_method(klass, "each", rpmmi_each, 0);
74  rb_define_method(klass, "next", rpmmi_next, 0);
75  rb_define_method(klass, "pattern", rpmmi_pattern, -1);
76 }
77 
78 /* --- Object properties */
79 static VALUE
81 {
82 if (_debug)
83 fprintf(stderr, "==> %s(0x%lx)\n", __FUNCTION__, s);
84  return INT2FIX(_debug);
85 }
86 
87 static VALUE
88 rpmmi_debug_set(VALUE s, VALUE v)
89 {
90  return INT2FIX(_debug = FIX2INT(v));
91 }
92 
93 static VALUE
95 {
96  rpmmi mi = rpmmi_ptr(s);
97  return INT2FIX(rpmmiCount(mi));
98 }
99 
100 static VALUE
102 {
103  rpmmi mi = rpmmi_ptr(s);
104  return INT2FIX(rpmmiInstance(mi));
105 }
106 
107 static void
108 initProperties(VALUE klass)
109 {
110  rb_define_method(klass, "debug", rpmmi_debug_get, 0);
111  rb_define_method(klass, "debug=", rpmmi_debug_set, 1);
112  rb_define_method(klass, "length", rpmmi_count_get, 0);
113  rb_define_method(klass, "count", rpmmi_count_get, 0);
114  rb_define_method(klass, "offset", rpmmi_offset_get, 0);
115  rb_define_method(klass, "instance", rpmmi_offset_get, 0);
116 }
117 
118 /* --- Object ctors/dtors */
119 static void
121 {
122 if (_debug)
123 fprintf(stderr, "==> %s(%p)\n", __FUNCTION__, mi);
124  mi = rpmmiFree(mi);
125 }
126 
127 static VALUE
128 rpmmi_new(int argc, VALUE *argv, VALUE s)
129 {
130  VALUE v_ts, v_tag, v_key;
131  rpmts ts;
132  rpmTag _tag = RPMDBI_PACKAGES;
133  void * _key = NULL;
134  int _len = 0;
135  rpmmi mi;
136 
137  rb_scan_args(argc, argv, "12", &v_ts, &v_tag, &v_key);
138 
139  ts = rpmmi_ptr(v_ts);
140  if (!NIL_P(v_tag))
141  _tag = FIX2INT(v_tag);
142  if (!NIL_P(v_key))
143  _key = StringValueCStr(v_key);
144 
145  mi = rpmtsInitIterator(ts, _tag, _key, _len);
146 
147 if (_debug)
148 fprintf(stderr, "==> %s(%p[%d], 0x%lx) mi %p\n", __FUNCTION__, argv, argc, s, mi);
149  return Data_Wrap_Struct(s, 0, rpmmi_free, mi);
150 }
151 
152 /* --- Class initialization */
153 
154 void
156 {
157  rpmmiClass = rb_define_class("Mi", rb_cObject);
158 if (_debug)
159 fprintf(stderr, "==> %s() rpmmiClass 0x%lx\n", __FUNCTION__, rpmmiClass);
160  rb_include_module(rpmmiClass, rb_mEnumerable);
161  rb_define_singleton_method(rpmmiClass, "new", rpmmi_new, -1);
164 }
165 
166 VALUE
167 rpmrb_NewMi(void * _ts, int _tag, void * _key, int _len)
168 {
169  rpmmi mi = rpmtsInitIterator(_ts, _tag, _key, _len);
170  return Data_Wrap_Struct(rpmmiClass, 0, rpmmi_free, mi);
171 }
static VALUE rpmmi_next(VALUE s)
Definition: rpmmi-rb.c:49
static VALUE rpmmi_pattern(int argc, VALUE *argv, VALUE s)
Definition: rpmmi-rb.c:57
uint32_t rpmmiInstance(rpmmi mi)
Return header instance for current position of rpmdb iterator.
Definition: rpmdb.c:1743
VALUE rpmrb_NewHdr(void *_h)
Definition: rpmhdr-rb.c:263
struct rpmts_s * rpmts
The RPM Transaction Set.
Definition: rpmtypes.h:14
The Header data structure.
static VALUE rpmmi_offset_get(VALUE s)
Definition: rpmmi-rb.c:101
static VALUE rpmmi_debug_get(VALUE s)
Definition: rpmmi-rb.c:80
Definition: rpmdb.c:436
enum rpmTag_e rpmTag
Definition: rpmtag.h:468
VALUE rpmmiClass
Definition: rpmmi-rb.c:23
void Init_rpmmi(void)
Definition: rpmmi-rb.c:155
Header headerLink(Header h)
Reference a header instance.
Header h
Definition: spec.c:739
argv
Definition: rpmmtree.c:3679
repo _ts
Definition: rpmrepo.c:164
exit Fhe p ptr
Definition: db3.c:2119
static VALUE rpmmi_each(VALUE s)
Definition: rpmmi-rb.c:39
rpmmi rpmmiFree(rpmmi mi)
Destroy rpm database iterator.
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
unsigned int rpmmiCount(rpmmi mi)
Return number of elements in rpm database iterator.
Definition: rpmdb.c:1759
Definition: rpmmtree.c:326
static VALUE rpmmi_count_get(VALUE s)
Definition: rpmmi-rb.c:94
RPM pattern matching.
Ruby bindings to the RPM Transaction Set API.
Header rpmmiNext(rpmmi mi)
Return next package header from iteration.
Definition: rpmdb.c:2248
int rpmmiAddPattern(rpmmi mi, rpmTag tag, rpmMireMode mode, const char *pattern)
Add pattern to iterator selector.
Definition: rpmdb.c:1906
static VALUE rpmmi_debug_set(VALUE s, VALUE v)
Definition: rpmmi-rb.c:88
static void initMethods(VALUE klass)
Definition: rpmmi-rb.c:71
RPM Ruby bindings &quot;RPM&quot; module.
static void rpmmi_free(rpmmi mi)
Definition: rpmmi-rb.c:120
const char * s
Definition: poptALL.c:734
static VALUE rpmmi_new(int argc, VALUE *argv, VALUE s)
Definition: rpmmi-rb.c:128
mi
Definition: rpmdb-py.c:159
Structures and prototypes used for an &quot;rpmts&quot; transaction set.
return NULL
Definition: poptALL.c:613
static void initProperties(VALUE klass)
Definition: rpmmi-rb.c:108
VALUE rpmrb_NewMi(void *_ts, int _tag, void *_key, int _len)
Definition: rpmmi-rb.c:167
static int _debug
Definition: rpmmi-rb.c:26
Access RPM indices using Berkeley DB interface(s).
static void * rpmmi_ptr(VALUE s)
Definition: rpmmi-rb.c:30
rpmmi rpmtsInitIterator(const rpmts ts, rpmTag rpmtag, const void *keyp, size_t keylen)
Return transaction database iterator.
Definition: rpmts.c:212
#define RPMDBI_PACKAGES
Pseudo-tags used by the rpmdb and rpmgi iterator API&#39;s.
Definition: rpmtag.h:477