rpm  5.4.14
rpmts-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 "spec-rb.h"
11 
12 #include <argv.h>
13 #include <mire.h>
14 
15 #include <rpmdb.h>
16 
17 #define _RPMTS_INTERNAL
18 #include <rpmts.h>
19 #include <rpmbuild.h>
20 #include <rpmrc.h>
21 
22 #include "../debug.h"
23 
24 
25 VALUE rpmtsClass;
26 
27 
28 /*@unchecked@*/
29 static int _debug = 0;
30 
31 
32 /* --- helpers */
33 
35 static void *
36 rpmts_ptr(VALUE s)
37 {
38  void *ptr;
39  Data_Get_Struct(s, void, ptr);
40  return ptr;
41 }
42 
43 
44 static VALUE
46 {
47  void *ptr = rpmts_ptr(s);
48  rpmts ts = ptr;
49  VALUE NVRA = rb_ary_new();
50  ARGV_t keys = NULL;
51  int nkeys;
52  int xx;
53  int i;
54 
55  if (ts->rdb == NULL)
56  (void) rpmtsOpenDB(ts, O_RDONLY);
57 
59  RPMMIRE_STRCMP, NULL, &keys);
60  nkeys = argvCount(keys);
61 
62  if (keys)
63  for (i = 0; i < nkeys; i++)
64  rb_ary_push(NVRA, rb_str_new2(keys[i]));
65 
66  if (_debug)
67  fprintf(stderr, "==> %s(0x%lx) ptr %p NVRA 0x%lx\n",
68  __FUNCTION__, s, ptr, NVRA);
69 
70  keys = argvFree(keys);
71  return NVRA;
72 }
73 
74 
75 /* --- Object methods */
76 static VALUE
77 rpmts_mi(int argc, VALUE *argv, VALUE s)
78 {
79  VALUE v_tag, v_key;
80  rpmts ts = rpmts_ptr(s);
81  rpmTag _tag = RPMDBI_PACKAGES;
82  void * _key = NULL;
83  int _len = 0;
84 
85  rb_scan_args(argc, argv, "02", &v_tag, &v_key);
86 
87  if (!NIL_P(v_tag))
88  _tag = FIX2INT(v_tag);
89  if (!NIL_P(v_key))
90  _key = StringValueCStr(v_key);
91 
92  return rpmrb_NewMi(ts, _tag, _key, _len);
93 }
94 
95 
122 static VALUE
123 rpmts_parse_spec(int argc, VALUE *argv, VALUE obj)
124 {
125  VALUE specfile_v, rootURL_v, recursing_v, passphrase_v, cookie_v,
126  anyarch_v, force_v, verify_v;
127  rb_scan_args(argc, argv, "8", &specfile_v, &rootURL_v, &recursing_v,
128  &passphrase_v, &cookie_v, &anyarch_v, &force_v, &verify_v);
129 
130  /* Check and pre-set arguments */
131 
132  Check_Type(specfile_v, T_STRING);
133  char *specfile = RSTRING_PTR(specfile_v);
134 
135  Check_Type(rootURL_v, T_STRING);
136  char *rootURL = RSTRING_PTR(rootURL_v);
137 
138  char *cookie = NULL;
139  switch(TYPE(cookie_v)) {
140  case T_STRING:
141  cookie = RSTRING_PTR(cookie_v);
142  break;
143  case T_NIL:
144  cookie = NULL;
145  break;
146  default:
147  rpm_rb_raise(1, "cookie must be either NIL or a string");
148  break;
149  }
150 
151  Check_Type(passphrase_v, T_STRING);
152  char *passphrase = RSTRING_PTR(passphrase_v);
153 
154  int recursing = 0;
155  switch(TYPE(recursing_v)) {
156  case T_TRUE:
157  recursing = 1;
158  break;
159  case T_FALSE:
160  recursing = 0;
161  break;
162  default:
163  rpm_rb_raise(1,
164  "Parameter 'recursing' must be either true or false");
165  break;
166  }
167 
168  int anyarch = 1;
169  switch(TYPE(anyarch_v)) {
170  case T_TRUE:
171  anyarch = 1;
172  break;
173  case T_FALSE:
174  anyarch = 0;
175  break;
176  default:
177  rpm_rb_raise(1,
178  "Parameter 'anyarch' must be either true or false");
179  break;
180  }
181 
182  int verify = 1;
183  switch(TYPE(verify_v)) {
184  case T_TRUE:
185  verify = 1;
186  break;
187  case T_FALSE:
188  verify = 0;
189  break;
190  default:
191  rpm_rb_raise(1,
192  "Parameter 'verify' must be either true or false");
193  break;
194  }
195 
196  int force = 0;
197  switch(TYPE(force_v)) {
198  case T_TRUE:
199  force = 1;
200  break;
201  case T_FALSE:
202  force = 0;
203  break;
204  default:
205  rpm_rb_raise(1,
206  "Parameter 'force' must be either true or false");
207  break;
208  }
209 
210 
211  rpmts ts = rpmts_ptr(obj);
212  int error = parseSpec(ts, specfile, rootURL,
213  recursing, passphrase, cookie, anyarch, force, verify);
214  if(error) {
215  rpm_rb_raise(error, "Could not parse spec file");
216  return Qnil;
217  }
218 
219  /* Wrap spec struct and set a reference to this ts class */
220 
221  VALUE spec_v = spec_wrap(rpmtsSpec(ts));
222  rb_iv_set(spec_v, "ts", obj);
223 
224  return spec_v;
225 }
226 
227 
228 static void
229 initMethods(VALUE klass)
230 {
231  rb_define_method(klass, "mi", &rpmts_mi, -1);
232  rb_define_method(klass, "parse_spec", &rpmts_parse_spec, -1);
233 }
234 
235 
236 /* --- Object properties */
237 static VALUE
239 {
240 if (_debug)
241 fprintf(stderr, "==> %s(0x%lx)\n", __FUNCTION__, s);
242  return INT2FIX(_debug);
243 }
244 
245 static VALUE
246 rpmts_debug_set(VALUE s, VALUE v)
247 {
248 if (_debug)
249 fprintf(stderr, "==> %s(0x%lx, 0x%lx)\n", __FUNCTION__, s, v);
250  return INT2FIX(_debug = FIX2INT(v));
251 }
252 
253 static VALUE
255 {
256  void *ptr = rpmts_ptr(s);
257  rpmts ts = ptr;
258 if (_debug)
259 fprintf(stderr, "==> %s(0x%lx) ptr %p\n", __FUNCTION__, s, ptr);
260  return rb_str_new2(rpmtsRootDir(ts));
261 }
262 
263 static VALUE
264 rpmts_rootdir_set(VALUE s, VALUE v)
265 {
266  void *ptr = rpmts_ptr(s);
267  rpmts ts = ptr;
268 if (_debug)
269 fprintf(stderr, "==> %s(0x%lx, 0x%lx) ptr %p\n", __FUNCTION__, s, v, ptr);
270  rpmtsSetRootDir(ts, StringValueCStr(v));
271  return rb_str_new2(rpmtsRootDir(ts));
272 }
273 
274 static VALUE
276 {
277  void *ptr = rpmts_ptr(s);
278  rpmts ts = ptr;
279 if (_debug)
280 fprintf(stderr, "==> %s(0x%lx) ptr %p\n", __FUNCTION__, s, ptr);
281  return INT2FIX(rpmtsVSFlags(ts));
282 }
283 
284 static VALUE
285 rpmts_vsflags_set(VALUE s, VALUE v)
286 {
287  void *ptr = rpmts_ptr(s);
288  rpmts ts = ptr;
289 if (_debug)
290 fprintf(stderr, "==> %s(0x%lx, 0x%lx) ptr %p\n", __FUNCTION__, s, v, ptr);
291  rpmtsSetVSFlags(ts, FIX2INT(v));
292  return INT2FIX(rpmtsVSFlags(ts));
293 }
294 
295 static VALUE
297 {
298  return rpmtsLoadNVRA(s);
299 }
300 
301 static void
302 initProperties(VALUE klass)
303 {
304  rb_define_method(klass, "debug", rpmts_debug_get, 0);
305  rb_define_method(klass, "debug=", rpmts_debug_set, 1);
306  rb_define_method(klass, "rootdir", rpmts_rootdir_get, 0);
307  rb_define_method(klass, "rootdir=", rpmts_rootdir_set, 1);
308  rb_define_method(klass, "vsflags", rpmts_vsflags_get, 0);
309  rb_define_method(klass, "vsflags=", rpmts_vsflags_set, 1);
310  rb_define_method(klass, "NVRA", rpmts_NVRA_get, 0);
311 }
312 
313 
314 /* --- Object ctors/dtors */
315 static void
317 {
318 if (_debug)
319 fprintf(stderr, "==> %s(%p)\n", __FUNCTION__, ts);
320  ts = rpmtsFree(ts);
321 }
322 
323 static VALUE
324 rpmts_new(int argc, VALUE *argv, VALUE s)
325 {
326  VALUE v_rootdir;
327  char * _rootdir = "/";
328  rpmts ts;
329 
330  rb_scan_args(argc, argv, "01", &v_rootdir);
331 
332  if (!NIL_P(v_rootdir))
333  _rootdir = StringValueCStr(v_rootdir);
334 
335  ts = rpmtsCreate();
336  rpmtsSetRootDir(ts, _rootdir);
337 
338 if (_debug)
339 fprintf(stderr, "==> %s(%p[%d], 0x%lx) ts %p\n", __FUNCTION__, argv, argc, s, ts
340 );
341  return Data_Wrap_Struct(s, 0, rpmts_free, ts);
342 }
343 
344 
345 /* --- Class initialization */
346 
347 
348 void
350 {
351  rpmtsClass = rb_define_class_under(rpmModule, "Ts", rb_cObject);
352 if (_debug)
353 fprintf(stderr, "==> %s() rpmtsClass 0x%lx\n", __FUNCTION__, rpmtsClass);
354 #ifdef NOTYET
355  rb_include_module(rpmtsClass, rb_mEnumerable);
356 #endif
357  rb_define_singleton_method(rpmtsClass, "new", &rpmts_new, -1);
360 }
char * cookie
Definition: rpmts-py.c:1341
int xx
Definition: spec.c:744
int verify
Definition: rpmts-py.c:1343
static VALUE rpmts_parse_spec(int argc, VALUE *argv, VALUE obj)
Parses a spec file and returns a new RPM::Spec object to access it.
Definition: rpmts-rb.c:123
static void initMethods(VALUE klass)
Definition: rpmts-rb.c:229
static void initProperties(VALUE klass)
Definition: rpmts-rb.c:302
int anyarch
Definition: rpmts-py.c:1342
static VALUE rpmts_debug_get(VALUE s)
Definition: rpmts-rb.c:238
struct rpmts_s * rpmts
The RPM Transaction Set.
Definition: rpmtypes.h:14
rpmdb rpmtsGetRdb(rpmts ts)
Get transaction set database handle.
Definition: pkgio.c:151
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
VALUE rpmtsClass
Consitutes the RPM::Ts class, binding to RPM&#39;s TransactionSet API.
Definition: rpmts-rb.c:25
enum rpmTag_e rpmTag
Definition: rpmtag.h:468
argv
Definition: rpmmtree.c:3679
static VALUE rpmts_rootdir_get(VALUE s)
Definition: rpmts-rb.c:254
exit Fhe p ptr
Definition: db3.c:2119
static VALUE rpmtsLoadNVRA(VALUE s)
Definition: rpmts-rb.c:45
int parseSpec(rpmts ts, const char *specFile, const char *rootURL, int recursing, const char *passPhrase, const char *cookie, int anyarch, int force, int verify)
Parse spec file into spec control structure.
Definition: parseSpec.c:530
static int _debug
Definition: rpmts-rb.c:29
rpmts rpmtsCreate(void)
Create an empty transaction set.
Definition: rpmts.c:1468
void rpmtsSetRootDir(rpmts ts, const char *rootDir)
Set transaction rootDir, i.e.
Definition: rpmts.c:925
VALUE spec_wrap(Spec spec)
Wraps an already existing Spec_s structure in a Ruby class.
Definition: spec-rb.c:210
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
Definition: rpmmtree.c:326
RPM pattern matching.
int argvCount(const ARGV_t argv)
Return no.
Definition: argv.c:71
void Init_rpmts(void)
Definition: rpmts-rb.c:349
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
Definition: argv.c:44
static VALUE rpmts_vsflags_get(VALUE s)
Definition: rpmts-rb.c:275
Ruby bindings to the RPM Transaction Set API.
const char * rpmtsRootDir(rpmts ts)
Get transaction rootDir, i.e.
Definition: rpmts.c:901
void rpm_rb_raise(rpmRC error, char *message)
Raises a Ruby exception (RPM::Error).
Definition: rpm-rb.c:53
int rpmtsOpenDB(rpmts ts, int dbmode)
Open the database used by the transaction.
Definition: rpmts.c:115
int recursing
Definition: rpmts-py.c:1339
static VALUE rpmts_rootdir_set(VALUE s, VALUE v)
Definition: rpmts-rb.c:264
fts keys
Definition: rpmmtree.c:3666
RPM Ruby bindings &quot;RPM&quot; module.
static void * rpmts_ptr(VALUE s)
Returns the RPMTS structure wrapped in a RPM::Ts ruby object.
Definition: rpmts-rb.c:36
Spec rpmtsSpec(rpmts ts)
Get spec control structure from transaction set.
Definition: rpmts.c:1376
rpmVSFlags rpmtsSetVSFlags(rpmts ts, rpmVSFlags vsflags)
Set verify signatures flag(s).
Definition: rpmts.c:843
const char * s
Definition: poptALL.c:734
This is the only module users of librpmbuild should need to include.
static void rpmts_free(rpmts ts)
Definition: rpmts-rb.c:316
int force
Definition: rpmts-py.c:1344
Structures and prototypes used for an &quot;rpmts&quot; transaction set.
rpmVSFlags rpmtsVSFlags(rpmts ts)
Get verify signatures flag(s).
Definition: rpmts.c:838
return NULL
Definition: poptALL.c:613
static VALUE rpmts_debug_set(VALUE s, VALUE v)
Definition: rpmts-rb.c:246
VALUE rpmModule
The &quot;RPM&quot; Ruby module.
Definition: rpm-rb.c:35
Ruby bindings for spec file access.
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
Definition: spec.c:737
VALUE rpmrb_NewMi(void *_ts, int _tag, void *_key, int _len)
Definition: rpmmi-rb.c:167
ARGstr_t * ARGV_t
Definition: argv.h:12
Access RPM indices using Berkeley DB interface(s).
int rpmdbMireApply(rpmdb db, rpmTag tag, rpmMireMode mode, const char *pat, const char ***argvp)
Return array of keys matching a pattern.
Definition: rpmdb.c:1482
static VALUE rpmts_vsflags_set(VALUE s, VALUE v)
Definition: rpmts-rb.c:285
static VALUE rpmts_mi(int argc, VALUE *argv, VALUE s)
Definition: rpmts-rb.c:77
int i
Definition: spec.c:743
#define RPMDBI_PACKAGES
Pseudo-tags used by the rpmdb and rpmgi iterator API&#39;s.
Definition: rpmtag.h:477
static VALUE rpmts_new(int argc, VALUE *argv, VALUE s)
Definition: rpmts-rb.c:324
static VALUE rpmts_NVRA_get(VALUE s)
Definition: rpmts-rb.c:296