ruby-rpm 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+ /* -*- mode: C; c-basic-offset: 4; tab-width: 4; -*- */
2
+ /* Ruby/RPM
3
+ *
4
+ * Copyright (C) 2002 Kenta MURATA <muraken2@nifty.com>.
5
+ */
6
+
7
+ /* $Id: private.h 17 2004-03-19 05:12:19Z zaki $ */
8
+
9
+ #define RPM_VERSION(maj,min,pl) (((maj) << 16) + ((min) << 8) + (pl))
10
+
11
+ #include <ctype.h>
12
+ #include <errno.h>
13
+ #include <fcntl.h>
14
+ #include <stdio.h>
15
+ #include <stdlib.h>
16
+ #include <string.h>
17
+ #include <sys/mman.h>
18
+ #include <sys/types.h>
19
+ #include <sys/stat.h>
20
+ #include <unistd.h>
21
+ #include <st.h>
22
+
23
+ #include <rpmcli.h>
24
+ #include <rpmlib.h>
25
+ #include <rpmdb.h>
26
+ #include <rpmbuild.h>
27
+ #include <rpmmessages.h>
28
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
29
+ #include <rpmts.h>
30
+ #include <rpmps.h>
31
+ #include <rpmds.h>
32
+ #include "rpm40_compat.h"
33
+ #endif
34
+
35
+ #include "ruby-rpm.h"
36
+
37
+ #define RPM_DB(v) (((rpm_db_t*)DATA_PTR((v)))->db)
38
+ #ifdef PKG_CACHE_TEST
39
+ #define RPM_HEADER(v) rpm_package_get_header(v)
40
+ #else
41
+ #define RPM_HEADER(v) ((Header)DATA_PTR((v)))
42
+ #endif
43
+ #define RPM_MI(v) (((rpm_mi_t*)DATA_PTR((v)))->mi)
44
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
45
+ #define RPM_SPEC(v) ((Spec)DATA_PTR((v)))
46
+ #else
47
+ #define RPM_SPEC(v) rpmtsSpec((rpmts)DATA_PTR((v)))
48
+ #endif
49
+ #define RPM_TRANSACTION(v) (((rpm_trans_t*)DATA_PTR((v)))->ts)
50
+ #define RPM_SCRIPT_FD(v) (((rpm_trans_t*)DATA_PTR((v)))->script_fd)
51
+
52
+ typedef struct {
53
+ rpmdb db;
54
+ int ref_count;
55
+ } rpm_db_t;
56
+
57
+ typedef struct {
58
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
59
+ rpmTransactionSet ts;
60
+ #else
61
+ rpmts ts;
62
+ #endif
63
+ FD_t script_fd;
64
+ rpm_db_t* db;
65
+ } rpm_trans_t;
66
+
67
+ typedef struct {
68
+ rpmdbMatchIterator mi;
69
+ rpm_db_t* db;
70
+ } rpm_mi_t;
71
+
72
+ /* db.c */
73
+ void Init_rpm_DB(void);
74
+ void Init_rpm_transaction(void);
75
+ void Init_rpm_MatchIterator(void);
76
+
77
+ /* dependency.c */
78
+ void Init_rpm_dependency(void);
79
+
80
+ /* file.c */
81
+ void Init_rpm_file(void);
82
+
83
+ /* package.c */
84
+ #ifdef PKG_CACHE_TEST
85
+ Header rpm_package_get_header(VALUE pkg);
86
+ #endif
87
+ void Init_rpm_package(void);
88
+
89
+ /* rpm.c */
90
+ VALUE ruby_rpm_make_temp_name(void);
91
+
92
+ /* source.c */
93
+ void Init_rpm_source(void);
94
+
95
+ /* spec.c */
96
+ void Init_rpm_spec(void);
97
+
98
+ /* version.c */
99
+ void Init_rpm_version(void);
100
+
101
+ static void inline
102
+ get_entry(Header hdr, rpmTag tag, rpmTagType* type, void** ptr)
103
+ {
104
+ if (!headerGetEntryMinMemory(
105
+ hdr, tag, (hTYP_t)type, (hPTR_t*)ptr, NULL)) {
106
+ *ptr = NULL;
107
+ }
108
+ }
109
+
110
+ static void inline
111
+ release_entry(rpmTagType type, void* ptr)
112
+ {
113
+ ptr = headerFreeData(ptr, type);
114
+ }
@@ -0,0 +1,660 @@
1
+ /* -*- mode: C; c-basic-offset: 4; tab-width: 4; -*- */
2
+ /* Ruby/RPM
3
+ *
4
+ * Copyright (C) 2002 Kenta MURATA <muraken2@nifty.com>.
5
+ */
6
+
7
+ /* $Id: rpm.c 9 2004-03-13 14:19:20Z zaki $ */
8
+
9
+ #include "private.h"
10
+
11
+ VALUE rpm_mRPM;
12
+
13
+ static VALUE
14
+ m_expand(VALUE m, VALUE name)
15
+ {
16
+ return rb_str_new2(rpmExpand(StringValueCStr(name), NULL));
17
+ }
18
+
19
+ static VALUE
20
+ m_aref(VALUE m, VALUE name)
21
+ {
22
+ char buf[BUFSIZ];
23
+ char* tmp;
24
+ VALUE val;
25
+
26
+ if (TYPE(name) != T_STRING) {
27
+ rb_raise(rb_eTypeError, "illegal argument type");
28
+ }
29
+
30
+ sprintf(buf, "%%{%s}", RSTRING(name)->ptr);
31
+ tmp = strdup(buf);
32
+ expandMacros(NULL, NULL, buf, BUFSIZ);
33
+ if (strcmp(tmp, buf) == 0) {
34
+ val = Qnil;
35
+ } else {
36
+ val = rb_str_new2(buf);
37
+ }
38
+ free(tmp);
39
+
40
+ return val;
41
+ }
42
+
43
+ VALUE
44
+ rpm_macro_aref(VALUE name)
45
+ {
46
+ return m_aref(Qnil, name);
47
+ }
48
+
49
+ static VALUE
50
+ m_aset(VALUE m, VALUE name, VALUE val)
51
+ {
52
+ if (TYPE(name) != T_STRING
53
+ || (val != Qnil && TYPE(val) != T_STRING)) {
54
+ rb_raise(rb_eTypeError, "illegal argument type(s)");
55
+ }
56
+ if (val == Qnil) {
57
+ delMacro(NULL, RSTRING(name)->ptr);
58
+ } else {
59
+ addMacro(NULL, RSTRING(name)->ptr, NULL, RSTRING(val)->ptr, RMIL_DEFAULT);
60
+ }
61
+ return Qnil;
62
+ }
63
+
64
+ VALUE
65
+ rpm_macro_aset(VALUE name, VALUE val)
66
+ {
67
+ return m_aset(Qnil, name, val);
68
+ }
69
+
70
+ static VALUE
71
+ m_readrc(int argc, VALUE* argv, VALUE m)
72
+ {
73
+ register int i;
74
+ char buf[BUFSIZ];
75
+
76
+ if (argc == 0) {
77
+ rb_raise(rb_eArgError, "too few argument(>= 1)");
78
+ }
79
+
80
+ buf[0] = '\0';
81
+ for (i = 0; i < argc; i++) {
82
+ if (TYPE(argv[i]) != T_STRING) {
83
+ rb_raise(rb_eTypeError, "illegal argument type(s)");
84
+ }
85
+ strcat(buf, RSTRING(argv[i])->ptr);
86
+ strcat(buf, ":");
87
+ }
88
+ rpmFreeMacros(NULL);
89
+ if (rpmReadConfigFiles(buf, NULL)) {
90
+ rb_raise(rb_eRuntimeError, "can not read rc file %s", buf);
91
+ }
92
+
93
+ return Qnil;
94
+ }
95
+
96
+ void
97
+ rpm_readrc(const char* rcpath)
98
+ {
99
+ VALUE argv[1];
100
+ argv[0] = rb_str_new2(rcpath);
101
+ m_readrc(1, argv, Qnil);
102
+ }
103
+
104
+ static VALUE
105
+ m_init_macros(int argc, VALUE* argv, VALUE m)
106
+ {
107
+ register int i;
108
+ char buf[BUFSIZ];
109
+
110
+ if (argc == 0) {
111
+ rb_raise(rb_eArgError, "too few argument(>= 1)");
112
+ }
113
+
114
+ buf[0] = '\0';
115
+ for (i = 0; i < argc; i++) {
116
+ if (TYPE(argv[i]) != T_STRING) {
117
+ rb_raise(rb_eTypeError, "illegal argument type(s)");
118
+ }
119
+ strcat(buf, RSTRING(argv[i])->ptr);
120
+ strcat(buf, ":");
121
+ }
122
+ rpmInitMacros(NULL, buf);
123
+
124
+ return Qnil;
125
+ }
126
+
127
+ void
128
+ rpm_init_marcros(const char* path)
129
+ {
130
+ VALUE argv[1];
131
+ argv[0] = rb_str_new2(path);
132
+ m_init_macros(1, argv, Qnil);
133
+ }
134
+
135
+ static int rpm_verbosity;
136
+
137
+ static VALUE
138
+ m_get_verbosity(VALUE m)
139
+ {
140
+ return INT2NUM(rpm_verbosity);
141
+ }
142
+
143
+ VALUE
144
+ rpm_get_verbosity(void)
145
+ {
146
+ return INT2NUM(rpm_verbosity);
147
+ }
148
+
149
+ static VALUE
150
+ m_set_verbosity(VALUE m, VALUE verbosity)
151
+ {
152
+ int v = NUM2INT(rb_Integer(verbosity));
153
+ switch (v) {
154
+ case RPMLOG_EMERG: case RPMLOG_ALERT:
155
+ case RPMLOG_CRIT: case RPMLOG_ERR:
156
+ case RPMLOG_WARNING: case RPMLOG_NOTICE:
157
+ case RPMLOG_INFO: case RPMLOG_DEBUG:
158
+ break;
159
+
160
+ default:
161
+ rb_raise(rb_eArgError, "invalid verbosity");
162
+ }
163
+ rpmSetVerbosity(v);
164
+ rpm_verbosity = v;
165
+ return Qnil;
166
+ }
167
+
168
+ void
169
+ rpm_set_verbosity(VALUE verbosity)
170
+ {
171
+ m_set_verbosity(Qnil, verbosity);
172
+ }
173
+
174
+ static VALUE ruby_rpm_temp_format = Qnil;
175
+
176
+ VALUE
177
+ ruby_rpm_make_temp_name(void)
178
+ {
179
+ static long num = 0;
180
+ VALUE argv[2] = { ruby_rpm_temp_format, Qnil };
181
+
182
+ argv[1] = INT2NUM(num++);
183
+ return rb_f_sprintf(2, argv);
184
+ }
185
+
186
+ void
187
+ Init_rpmmodule(void)
188
+ {
189
+ char* temp;
190
+
191
+ rpm_mRPM = rb_define_module("RPM");
192
+
193
+ rb_define_const(rpm_mRPM, "VERSION", rb_str_new2(RUBY_RPM_VERSION));
194
+
195
+ #define DEF_LOG(name) \
196
+ rb_define_const(rpm_mRPM, "LOG_"#name, INT2NUM(RPMLOG_##name))
197
+ DEF_LOG(EMERG);
198
+ DEF_LOG(ALERT);
199
+ DEF_LOG(CRIT);
200
+ DEF_LOG(ERR);
201
+ DEF_LOG(WARNING);
202
+ DEF_LOG(NOTICE);
203
+ DEF_LOG(INFO);
204
+ DEF_LOG(DEBUG);
205
+ #undef DEF_LOG
206
+
207
+ #define DEF_MESS(name) \
208
+ rb_define_const(rpm_mRPM, "MESS_"#name, INT2NUM(RPMMESS_##name))
209
+ DEF_MESS(DEBUG);
210
+ DEF_MESS(VERBOSE);
211
+ DEF_MESS(NORMAL);
212
+ DEF_MESS(WARNING);
213
+ DEF_MESS(ERROR);
214
+ DEF_MESS(FATALERROR);
215
+ DEF_MESS(QUIET);
216
+ #undef DEF_MESS
217
+
218
+ #define DEFINE_DBI(name) \
219
+ rb_define_const(rpm_mRPM, "DBI_"#name, INT2NUM(RPMDBI_##name))
220
+ DEFINE_DBI(PACKAGES);
221
+ DEFINE_DBI(DEPENDS);
222
+ DEFINE_DBI(LABEL);
223
+ DEFINE_DBI(ADDED);
224
+ DEFINE_DBI(REMOVED);
225
+ DEFINE_DBI(AVAILABLE);
226
+ #undef DEFINE_DBI
227
+
228
+ #define DEFINE_TAG(name) \
229
+ rb_define_const(rpm_mRPM, "TAG_"#name, INT2NUM(RPMTAG_##name))
230
+ DEFINE_TAG(HEADERIMAGE);
231
+ DEFINE_TAG(HEADERSIGNATURES);
232
+ DEFINE_TAG(HEADERIMMUTABLE);
233
+ DEFINE_TAG(HEADERREGIONS);
234
+ DEFINE_TAG(HEADERI18NTABLE);
235
+ DEFINE_TAG(SIGSIZE);
236
+ DEFINE_TAG(SIGPGP);
237
+ DEFINE_TAG(SIGMD5);
238
+ DEFINE_TAG(SIGGPG);
239
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
240
+ DEFINE_TAG(PUBKEYS);
241
+ DEFINE_TAG(DSAHEADER);
242
+ DEFINE_TAG(RSAHEADER);
243
+ #endif
244
+ DEFINE_TAG(SHA1HEADER);
245
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
246
+ DEFINE_TAG(HDRID);
247
+ #endif
248
+ DEFINE_TAG(NAME);
249
+ DEFINE_TAG(VERSION);
250
+ DEFINE_TAG(RELEASE);
251
+ DEFINE_TAG(EPOCH);
252
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
253
+ DEFINE_TAG(N);
254
+ DEFINE_TAG(V);
255
+ DEFINE_TAG(R);
256
+ DEFINE_TAG(E);
257
+ #endif
258
+ DEFINE_TAG(SUMMARY);
259
+ DEFINE_TAG(DESCRIPTION);
260
+ DEFINE_TAG(BUILDTIME);
261
+ DEFINE_TAG(BUILDHOST);
262
+ DEFINE_TAG(INSTALLTIME);
263
+ DEFINE_TAG(SIZE);
264
+ DEFINE_TAG(DISTRIBUTION);
265
+ DEFINE_TAG(VENDOR);
266
+ DEFINE_TAG(GIF);
267
+ DEFINE_TAG(XPM);
268
+ DEFINE_TAG(LICENSE);
269
+ DEFINE_TAG(PACKAGER);
270
+ DEFINE_TAG(GROUP);
271
+ DEFINE_TAG(SOURCE);
272
+ DEFINE_TAG(PATCH);
273
+ DEFINE_TAG(URL);
274
+ DEFINE_TAG(OS);
275
+ DEFINE_TAG(ARCH);
276
+ DEFINE_TAG(PREIN);
277
+ DEFINE_TAG(POSTIN);
278
+ DEFINE_TAG(PREUN);
279
+ DEFINE_TAG(POSTUN);
280
+ DEFINE_TAG(FILESIZES);
281
+ DEFINE_TAG(FILESTATES);
282
+ DEFINE_TAG(FILEMODES);
283
+ DEFINE_TAG(FILERDEVS);
284
+ DEFINE_TAG(FILEMTIMES);
285
+ DEFINE_TAG(FILEMD5S);
286
+ DEFINE_TAG(FILELINKTOS);
287
+ DEFINE_TAG(FILEFLAGS);
288
+ DEFINE_TAG(FILEUSERNAME);
289
+ DEFINE_TAG(FILEGROUPNAME);
290
+ DEFINE_TAG(ICON);
291
+ DEFINE_TAG(SOURCERPM);
292
+ DEFINE_TAG(FILEVERIFYFLAGS);
293
+ DEFINE_TAG(ARCHIVESIZE);
294
+ DEFINE_TAG(PROVIDENAME);
295
+ DEFINE_TAG(REQUIREFLAGS);
296
+ DEFINE_TAG(REQUIRENAME);
297
+ DEFINE_TAG(REQUIREVERSION);
298
+ DEFINE_TAG(CONFLICTFLAGS);
299
+ DEFINE_TAG(CONFLICTNAME);
300
+ DEFINE_TAG(CONFLICTVERSION);
301
+ DEFINE_TAG(EXCLUDEARCH);
302
+ DEFINE_TAG(EXCLUDEOS);
303
+ DEFINE_TAG(EXCLUSIVEARCH);
304
+ DEFINE_TAG(EXCLUSIVEOS);
305
+ DEFINE_TAG(RPMVERSION);
306
+ DEFINE_TAG(TRIGGERSCRIPTS);
307
+ DEFINE_TAG(TRIGGERNAME);
308
+ DEFINE_TAG(TRIGGERVERSION);
309
+ DEFINE_TAG(TRIGGERFLAGS);
310
+ DEFINE_TAG(TRIGGERINDEX);
311
+ DEFINE_TAG(VERIFYSCRIPT);
312
+ DEFINE_TAG(CHANGELOGTIME);
313
+ DEFINE_TAG(CHANGELOGNAME);
314
+ DEFINE_TAG(CHANGELOGTEXT);
315
+ DEFINE_TAG(PREINPROG);
316
+ DEFINE_TAG(POSTINPROG);
317
+ DEFINE_TAG(PREUNPROG);
318
+ DEFINE_TAG(POSTUNPROG);
319
+ DEFINE_TAG(BUILDARCHS);
320
+ DEFINE_TAG(OBSOLETENAME);
321
+ DEFINE_TAG(VERIFYSCRIPTPROG);
322
+ DEFINE_TAG(TRIGGERSCRIPTPROG);
323
+ DEFINE_TAG(COOKIE);
324
+ DEFINE_TAG(FILEDEVICES);
325
+ DEFINE_TAG(FILEINODES);
326
+ DEFINE_TAG(FILELANGS);
327
+ DEFINE_TAG(PREFIXES);
328
+ DEFINE_TAG(INSTPREFIXES);
329
+ DEFINE_TAG(PROVIDEFLAGS);
330
+ DEFINE_TAG(PROVIDEVERSION);
331
+ DEFINE_TAG(OBSOLETEFLAGS);
332
+ DEFINE_TAG(OBSOLETEVERSION);
333
+ DEFINE_TAG(DIRINDEXES);
334
+ DEFINE_TAG(BASENAMES);
335
+ DEFINE_TAG(DIRNAMES);
336
+ DEFINE_TAG(OPTFLAGS);
337
+ DEFINE_TAG(DISTURL);
338
+ DEFINE_TAG(PAYLOADFORMAT);
339
+ DEFINE_TAG(PAYLOADCOMPRESSOR);
340
+ DEFINE_TAG(PAYLOADFLAGS);
341
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
342
+ DEFINE_TAG(MULTILIBS);
343
+ #endif
344
+ DEFINE_TAG(INSTALLTID);
345
+ DEFINE_TAG(REMOVETID);
346
+ DEFINE_TAG(RHNPLATFORM);
347
+ DEFINE_TAG(PLATFORM);
348
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
349
+ DEFINE_TAG(CACHECTIME);
350
+ DEFINE_TAG(CACHEPKGPATH);
351
+ DEFINE_TAG(CACHEPKGSIZE);
352
+ DEFINE_TAG(CACHEPKGMTIME);
353
+ DEFINE_TAG(FILECOLORS);
354
+ DEFINE_TAG(FILECLASS);
355
+ DEFINE_TAG(CLASSDICT);
356
+ DEFINE_TAG(FILEDEPENDSX);
357
+ DEFINE_TAG(FILEDEPENDSN);
358
+ DEFINE_TAG(DEPENDSDICT);
359
+ DEFINE_TAG(SOURCEPKGID);
360
+ #endif
361
+ #undef DEFINE_TAG
362
+
363
+ #define DEFINE_FILE_STATE(name) \
364
+ rb_define_const(rpm_mRPM, "FILE_STATE_"#name, INT2NUM(RPMFILE_STATE_##name))
365
+ DEFINE_FILE_STATE(NORMAL);
366
+ DEFINE_FILE_STATE(REPLACED);
367
+ DEFINE_FILE_STATE(NOTINSTALLED);
368
+ DEFINE_FILE_STATE(NETSHARED);
369
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
370
+ DEFINE_FILE_STATE(WRONGCOLOR);
371
+ #endif
372
+ #undef DEFILE_FILE_STATE
373
+
374
+ #define DEFINE_FILE(name) \
375
+ rb_define_const(rpm_mRPM, "FILE_"#name, INT2NUM(RPMFILE_##name))
376
+ DEFINE_FILE(NONE);
377
+ DEFINE_FILE(CONFIG);
378
+ DEFINE_FILE(DOC);
379
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
380
+ DEFINE_FILE(DONOTUSE);
381
+ #endif
382
+ DEFINE_FILE(MISSINGOK);
383
+ DEFINE_FILE(NOREPLACE);
384
+ DEFINE_FILE(SPECFILE);
385
+ DEFINE_FILE(GHOST);
386
+ DEFINE_FILE(LICENSE);
387
+ DEFINE_FILE(README);
388
+ DEFINE_FILE(EXCLUDE);
389
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
390
+ DEFINE_FILE(MULTILIB_SHIFT);
391
+ DEFINE_FILE(MULTILIB_MASK);
392
+ #endif
393
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
394
+ DEFINE_FILE(UNPATCHED);
395
+ DEFINE_FILE(PUBKEY);
396
+ #endif
397
+ DEFINE_FILE(ALL);
398
+ #undef DEFINE_FILE
399
+
400
+ #define DEFINE_SENSE(name) \
401
+ rb_define_const(rpm_mRPM, "SENSE_"#name, INT2NUM(RPMSENSE_##name))
402
+ DEFINE_SENSE(ANY);
403
+ DEFINE_SENSE(SERIAL);
404
+ DEFINE_SENSE(LESS);
405
+ DEFINE_SENSE(GREATER);
406
+ DEFINE_SENSE(EQUAL);
407
+ DEFINE_SENSE(PROVIDES);
408
+ DEFINE_SENSE(CONFLICTS);
409
+ DEFINE_SENSE(PREREQ);
410
+ DEFINE_SENSE(OBSOLETES);
411
+ DEFINE_SENSE(INTERP);
412
+ DEFINE_SENSE(SCRIPT_PRE);
413
+ DEFINE_SENSE(SCRIPT_POST);
414
+ DEFINE_SENSE(SCRIPT_PREUN);
415
+ DEFINE_SENSE(SCRIPT_POSTUN);
416
+ DEFINE_SENSE(SCRIPT_VERIFY);
417
+ DEFINE_SENSE(FIND_REQUIRES);
418
+ DEFINE_SENSE(FIND_PROVIDES);
419
+ DEFINE_SENSE(TRIGGERIN);
420
+ DEFINE_SENSE(TRIGGERUN);
421
+ DEFINE_SENSE(TRIGGERPOSTUN);
422
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
423
+ DEFINE_SENSE(MULTILIB);
424
+ #endif
425
+ DEFINE_SENSE(SCRIPT_PREP);
426
+ DEFINE_SENSE(SCRIPT_BUILD);
427
+ DEFINE_SENSE(SCRIPT_INSTALL);
428
+ DEFINE_SENSE(SCRIPT_CLEAN);
429
+ DEFINE_SENSE(RPMLIB);
430
+ DEFINE_SENSE(TRIGGERPREIN);
431
+ DEFINE_SENSE(KEYRING);
432
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
433
+ DEFINE_SENSE(TRIGGER);
434
+ #endif
435
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
436
+ #if defined(RPMSENSE_PATCHES)
437
+ DEFINE_SENSE(PATCHES);
438
+ #endif
439
+ DEFINE_SENSE(CONFIG);
440
+ #endif
441
+ #undef DEFINE_SENSE
442
+
443
+ #define DEF_PROB(name) \
444
+ rb_define_const(rpm_mRPM, "PROB_"#name, INT2NUM(RPMPROB_##name))
445
+ DEF_PROB(BADARCH);
446
+ DEF_PROB(BADOS);
447
+ DEF_PROB(PKG_INSTALLED);
448
+ DEF_PROB(BADRELOCATE);
449
+ DEF_PROB(REQUIRES);
450
+ DEF_PROB(CONFLICT);
451
+ DEF_PROB(NEW_FILE_CONFLICT);
452
+ DEF_PROB(FILE_CONFLICT);
453
+ DEF_PROB(OLDPACKAGE);
454
+ DEF_PROB(DISKSPACE);
455
+ DEF_PROB(DISKNODES);
456
+ DEF_PROB(BADPRETRANS);
457
+ #undef DEF_PROB
458
+
459
+ #define DEF_CALLBACK(name) \
460
+ rb_define_const(rpm_mRPM, "CALLBACK_"#name, INT2NUM(RPMCALLBACK_##name))
461
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
462
+ DEF_CALLBACK(UNKNOWN);
463
+ #endif
464
+ DEF_CALLBACK(INST_PROGRESS);
465
+ DEF_CALLBACK(INST_START);
466
+ DEF_CALLBACK(INST_OPEN_FILE);
467
+ DEF_CALLBACK(INST_CLOSE_FILE);
468
+ DEF_CALLBACK(TRANS_PROGRESS);
469
+ DEF_CALLBACK(TRANS_START);
470
+ DEF_CALLBACK(TRANS_STOP);
471
+ DEF_CALLBACK(UNINST_PROGRESS);
472
+ DEF_CALLBACK(UNINST_START);
473
+ DEF_CALLBACK(UNINST_STOP);
474
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
475
+ DEF_CALLBACK(REPACKAGE_PROGRESS);
476
+ DEF_CALLBACK(REPACKAGE_START);
477
+ DEF_CALLBACK(REPACKAGE_STOP);
478
+ DEF_CALLBACK(UNPACK_ERROR);
479
+ DEF_CALLBACK(CPIO_ERROR);
480
+ #endif
481
+ #undef DEF_CALLBACK
482
+
483
+ #define DEF_TRANS_FLAG(name) \
484
+ rb_define_const(rpm_mRPM, "TRANS_FLAG_"#name, INT2NUM(RPMTRANS_FLAG_##name))
485
+ DEF_TRANS_FLAG(NONE);
486
+ DEF_TRANS_FLAG(TEST);
487
+ DEF_TRANS_FLAG(BUILD_PROBS);
488
+ DEF_TRANS_FLAG(NOSCRIPTS);
489
+ DEF_TRANS_FLAG(JUSTDB);
490
+ DEF_TRANS_FLAG(NOTRIGGERS);
491
+ DEF_TRANS_FLAG(NODOCS);
492
+ DEF_TRANS_FLAG(ALLFILES);
493
+ DEF_TRANS_FLAG(KEEPOBSOLETE);
494
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
495
+ DEF_TRANS_FLAG(MULTILIB);
496
+ #endif
497
+ DEF_TRANS_FLAG(DIRSTASH);
498
+ DEF_TRANS_FLAG(REPACKAGE);
499
+ DEF_TRANS_FLAG(PKGCOMMIT);
500
+ DEF_TRANS_FLAG(PKGUNDO);
501
+ DEF_TRANS_FLAG(COMMIT);
502
+ DEF_TRANS_FLAG(UNDO);
503
+ DEF_TRANS_FLAG(REVERSE);
504
+ DEF_TRANS_FLAG(NOTRIGGERPREIN);
505
+ DEF_TRANS_FLAG(NOPRE);
506
+ DEF_TRANS_FLAG(NOPOST);
507
+ DEF_TRANS_FLAG(NOTRIGGERIN);
508
+ DEF_TRANS_FLAG(NOTRIGGERUN);
509
+ DEF_TRANS_FLAG(NOPREUN);
510
+ DEF_TRANS_FLAG(NOPOSTUN);
511
+ DEF_TRANS_FLAG(NOTRIGGERPOSTUN);
512
+ DEF_TRANS_FLAG(NOPAYLOAD);
513
+ DEF_TRANS_FLAG(APPLYONLY);
514
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
515
+ DEF_TRANS_FLAG(CHAINSAW);
516
+ #else
517
+ DEF_TRANS_FLAG(ANACONDA);
518
+ #endif
519
+ /* NOMD5 is not in jbj's 4.4.6 any more - Mandriva uses that */
520
+ #ifdef RPMTRANS_FLAG_NOMD5
521
+ DEF_TRANS_FLAG(NOMD5);
522
+ #endif
523
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
524
+ DEF_TRANS_FLAG(NOSUGGEST);
525
+ DEF_TRANS_FLAG(ADDINDEPS);
526
+ DEF_TRANS_FLAG(NOCONFIGS);
527
+ #endif
528
+ #undef DEF_TRANS_FLAG
529
+
530
+ #define DEF_PROB_FILTER(name) \
531
+ rb_define_const(rpm_mRPM, "PROB_FILTER_"#name, INT2NUM(RPMPROB_FILTER_##name))
532
+ DEF_PROB_FILTER(NONE);
533
+ DEF_PROB_FILTER(IGNOREOS);
534
+ DEF_PROB_FILTER(IGNOREARCH);
535
+ DEF_PROB_FILTER(REPLACEPKG);
536
+ DEF_PROB_FILTER(FORCERELOCATE);
537
+ DEF_PROB_FILTER(REPLACENEWFILES);
538
+ DEF_PROB_FILTER(REPLACEOLDFILES);
539
+ DEF_PROB_FILTER(OLDPACKAGE);
540
+ DEF_PROB_FILTER(DISKSPACE);
541
+ DEF_PROB_FILTER(DISKNODES);
542
+ #undef DEF_PROB_FILTER
543
+
544
+ rb_define_const(rpm_mRPM, "PROB_FILER_FORCE",
545
+ INT2NUM(RPMPROB_FILTER_REPLACEPKG
546
+ | RPMPROB_FILTER_REPLACENEWFILES
547
+ | RPMPROB_FILTER_REPLACEOLDFILES));
548
+ rb_define_const(rpm_mRPM, "PROB_FILER_REPLACEFILES",
549
+ INT2NUM(RPMPROB_FILTER_REPLACENEWFILES
550
+ | RPMPROB_FILTER_REPLACEOLDFILES));
551
+ rb_define_const(rpm_mRPM, "PROB_FILER_IGNORESIZE",
552
+ INT2NUM(RPMPROB_FILTER_DISKSPACE
553
+ | RPMPROB_FILTER_DISKNODES));
554
+
555
+ #define DEF_BUILD(name) \
556
+ rb_define_const(rpm_mRPM, "BUILD_"#name, INT2NUM(RPMBUILD_##name))
557
+ DEF_BUILD(NONE);
558
+ DEF_BUILD(PREP);
559
+ DEF_BUILD(BUILD);
560
+ DEF_BUILD(INSTALL);
561
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
562
+ DEF_BUILD(CHECK);
563
+ #endif
564
+ DEF_BUILD(CLEAN);
565
+ DEF_BUILD(FILECHECK);
566
+ DEF_BUILD(PACKAGESOURCE);
567
+ DEF_BUILD(PACKAGEBINARY);
568
+ DEF_BUILD(RMSOURCE);
569
+ DEF_BUILD(RMBUILD);
570
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
571
+ DEF_BUILD(STRINGBUF);
572
+ #endif
573
+ DEF_BUILD(RMSPEC);
574
+ #undef DEF_BUILD
575
+
576
+ rb_define_const(rpm_mRPM, "BUILD__UNTIL_PREP",
577
+ INT2NUM(RPMBUILD_PREP));
578
+ rb_define_const(rpm_mRPM, "BUILD__UNTIL_BUILD",
579
+ INT2NUM(RPMBUILD_PREP
580
+ | RPMBUILD_BUILD));
581
+ rb_define_const(rpm_mRPM, "BUILD__UNTIL_INSTALL",
582
+ INT2NUM(RPMBUILD_PREP
583
+ | RPMBUILD_BUILD
584
+ | RPMBUILD_INSTALL));
585
+ rb_define_const(rpm_mRPM, "BUILD__BINARY_PACKAGE",
586
+ INT2NUM(RPMBUILD_PREP
587
+ | RPMBUILD_BUILD
588
+ | RPMBUILD_INSTALL
589
+ | RPMBUILD_PACKAGEBINARY
590
+ | RPMBUILD_CLEAN));
591
+ rb_define_const(rpm_mRPM, "BUILD__SOURCE_PACKAGE",
592
+ INT2NUM(RPMBUILD_PREP
593
+ | RPMBUILD_BUILD
594
+ | RPMBUILD_INSTALL
595
+ | RPMBUILD_PACKAGESOURCE
596
+ | RPMBUILD_CLEAN));
597
+ rb_define_const(rpm_mRPM, "BUILD__ALL_PACKAGE",
598
+ INT2NUM(RPMBUILD_PREP
599
+ | RPMBUILD_BUILD
600
+ | RPMBUILD_INSTALL
601
+ | RPMBUILD_PACKAGEBINARY
602
+ | RPMBUILD_PACKAGESOURCE
603
+ | RPMBUILD_CLEAN));
604
+ rb_define_const(rpm_mRPM, "BUILD__CHECK_FILELIST",
605
+ INT2NUM(RPMBUILD_PREP
606
+ | RPMBUILD_BUILD
607
+ | RPMBUILD_INSTALL
608
+ | RPMBUILD_FILECHECK));
609
+
610
+ #define DEF_MIRE(name) \
611
+ rb_define_const(rpm_mRPM, "MIRE_"#name, INT2NUM(RPMMIRE_##name))
612
+ DEF_MIRE(DEFAULT);
613
+ DEF_MIRE(STRCMP);
614
+ DEF_MIRE(REGEX);
615
+ DEF_MIRE(GLOB);
616
+ #undef DEF_MIRE
617
+
618
+ rb_define_module_function(rpm_mRPM, "expand", m_expand, 1);
619
+ rb_define_module_function(rpm_mRPM, "[]", m_aref, 1);
620
+ rb_define_module_function(rpm_mRPM, "[]=", m_aset, 2);
621
+ rb_define_module_function(rpm_mRPM, "readrc", m_readrc, -1);
622
+ rb_define_module_function(rpm_mRPM, "init_macros", m_init_macros, -1);
623
+ rb_define_module_function(rpm_mRPM, "verbosity", m_get_verbosity, 0);
624
+ rb_define_module_function(rpm_mRPM, "verbosity=", m_set_verbosity, 1);
625
+
626
+ Init_rpm_DB();
627
+ Init_rpm_dependency();
628
+ Init_rpm_file();
629
+ Init_rpm_package();
630
+ Init_rpm_source();
631
+ Init_rpm_spec();
632
+ Init_rpm_transaction();
633
+ Init_rpm_version();
634
+ Init_rpm_MatchIterator();
635
+
636
+ temp = getenv("TMPDIR");
637
+ if (!temp) {
638
+ temp = getenv("TMP");
639
+ }
640
+ if (!temp) {
641
+ temp = getenv("TEMP");
642
+ }
643
+ if (!temp) {
644
+ temp = "/tmp";
645
+ } else {
646
+ char * tmpdir;
647
+ tmpdir = strchr(temp, '=');
648
+ if(tmpdir) temp = tmpdir + 1;
649
+ }
650
+
651
+ ruby_rpm_temp_format = rb_str_new2(temp);
652
+ temp = ALLOCA_N(char, 32);
653
+ sprintf(temp, "/ruby-rpm.%u.%%d", getpid());
654
+ rb_str_concat(ruby_rpm_temp_format, rb_str_new2(temp));
655
+ rb_gc_register_address(&ruby_rpm_temp_format);
656
+
657
+ rpmReadConfigFiles(NULL, NULL);
658
+ rpmInitMacros(NULL, macrofiles);
659
+ rpmSetVerbosity(RPMLOG_EMERG);
660
+ }