rpm  5.4.14
parseReqs.c
Go to the documentation of this file.
1 
6 #include "system.h"
7 
8 #include <rpmio.h>
9 #include <rpmiotypes.h>
10 #include <rpmlog.h>
11 #define _RPMEVR_INTERNAL
12 #include "rpmbuild.h"
13 #include "debug.h"
14 
15 /*@access EVR_t @*/
16 
17 #define SKIPWHITE(_x) {while(*(_x) && (xisspace(*_x) || *(_x) == ',')) (_x)++;}
18 #define SKIPNONWHITE(_x){while(*(_x) &&!(xisspace(*_x) || *(_x) == ',')) (_x)++;}
19 
20 rpmRC parseRCPOT(Spec spec, Package pkg, const char *field, rpmTag tagN,
21  rpmuint32_t index, rpmsenseFlags tagflags)
22 {
23  EVR_t evr = alloca(sizeof(*evr));
24  const char *r, *re, *v, *ve;
25  char * N = NULL;
26  char * EVR = NULL;
28  Header h;
29  rpmRC rc = RPMRC_FAIL; /* assume failure */
30  int ix;
31 
32  switch (tagN) {
34  tagflags |= RPMSENSE_PROVIDES;
35  h = pkg->header;
36  break;
38  tagflags |= RPMSENSE_OBSOLETES;
39  h = pkg->header;
40  break;
42  tagflags |= RPMSENSE_CONFLICTS;
43  h = pkg->header;
44  break;
46  tagflags |= RPMSENSE_CONFLICTS;
47  h = spec->sourceHeader;
48  break;
49  case RPMTAG_PREREQ:
50  tagflags |= RPMSENSE_ANY;
51  h = pkg->header;
52  break;
54  tagflags |= RPMSENSE_TRIGGERPREIN;
55  h = pkg->header;
56  break;
57  case RPMTAG_TRIGGERIN:
58  tagflags |= RPMSENSE_TRIGGERIN;
59  h = pkg->header;
60  break;
62  tagflags |= RPMSENSE_TRIGGERPOSTUN;
63  h = pkg->header;
64  break;
65  case RPMTAG_TRIGGERUN:
66  tagflags |= RPMSENSE_TRIGGERUN;
67  h = pkg->header;
68  break;
71  tagflags |= RPMSENSE_MISSINGOK;
72  h = spec->sourceHeader;
73  break;
74  case RPMTAG_BUILDPREREQ:
76  tagflags |= RPMSENSE_ANY;
77  h = spec->sourceHeader;
78  break;
80  tagflags |= RPMSENSE_PROVIDES;
81  h = spec->sourceHeader;
82  break;
84  tagflags |= RPMSENSE_OBSOLETES;
85  h = spec->sourceHeader;
86  break;
87  default:
89  tagflags |= RPMSENSE_ANY;
90  h = pkg->header;
91  break;
92  }
93 
94  for (r = field; *r != '\0'; r = re) {
95  size_t nr;
96  SKIPWHITE(r);
97  if (*r == '\0')
98  break;
99 
100  Flags = (tagflags & ~RPMSENSE_SENSEMASK);
101 
102  re = r;
103  SKIPNONWHITE(re);
104  N = xmalloc((re-r) + 1);
105  strncpy(N, r, (re-r));
106  N[re-r] = '\0';
107 
108  /* N must begin with alphanumeric, _, or /, or a macro. */
109  nr = strlen(N);
110  ix = 0;
111  if (N[ix] == '!')
112  ix++;
113  if (!(xisalnum(N[ix]) || N[ix] == '_' || N[ix] == '/'
114  || (nr > 5 && N[ix] == '%' && N[ix+1] == '{' && N[nr-1] == '}')))
115  {
117  _("line %d: Dependency \"%s\" must begin with alpha-numeric, '_' or '/': %s\n"),
118  spec->lineNum, N, spec->line);
119  goto exit;
120  }
121 
122  /* Parse EVR */
123  v = re;
124  SKIPWHITE(v);
125  ve = v;
126  SKIPNONWHITE(ve);
127 
128  re = v; /* ==> next token (if no EVR found) starts here */
129 
130  /* Check for possible logical operator */
131  if (ve > v) {
132 /*@-mods@*/
133  rpmsenseFlags F = rpmEVRflags(v, &ve);
134 /*@=mods@*/
135  if (F && r[0] == '/') {
137  _("line %d: Versioned file name not permitted: %s\n"),
138  spec->lineNum, spec->line);
139  goto exit;
140  }
141  if (F) {
142  /* now parse EVR */
143  v = ve;
144  SKIPWHITE(v);
145  ve = v;
146  SKIPNONWHITE(ve);
147  }
148  Flags &= ~RPMSENSE_SENSEMASK;
149  Flags |= F;
150  }
151 
152  if (Flags & RPMSENSE_SENSEMASK) {
153  char * t;
154 
155  EVR = t = xmalloc((ve-v) + 1);
156  nr = 0;
157  while (v < ve && *v != '\0')
158  switch ((int)*v) {
159  case '-': nr++; /*@fallthrough@*/
160  default: *t++ = *v++; break;
161  }
162  *t = '\0';
163 
164  if (*EVR == '\0') {
165  rpmlog(RPMLOG_ERR, _("line %d: %s must be specified: %s\n"),
166  spec->lineNum, "EVR", spec->line);
167  goto exit;
168  }
169  if (nr > 1) {
170  rpmlog(RPMLOG_ERR, _("line %d: Illegal char '-' in %s: %s\n"),
171  spec->lineNum, "EVR", spec->line);
172  goto exit;
173  }
174  /* EVR must be parseable (or a macro). */
175  ix = 0;
176  nr = strlen(EVR);
177  if (!(nr > 3 && EVR[0] == '%' && EVR[1] == '{' && EVR[nr-1] == '}'))
178  {
179  memset(evr, 0, sizeof(*evr));
180  ix = rpmEVRparse(EVR, evr);
181  evr->str = _free(evr->str);
182  }
183  if (ix != 0) {
184  rpmlog(RPMLOG_ERR, _("line %d: %s does not parse: %s\n"),
185  spec->lineNum, "EVR", spec->line);
186  goto exit;
187  }
188  re = ve; /* ==> next token after EVR string starts here */
189  } else
190  EVR = NULL;
191 
192  (void) addReqProv(spec, h, tagN, N, EVR, Flags, index);
193 
194  N = _free(N);
195  EVR = _free(EVR);
196 
197  }
198  rc = RPMRC_OK;
199 
200 exit:
201  N = _free(N);
202  EVR = _free(EVR);
203  return rc;
204 }
rpmlog(RPMLOG_ERR,"%s\n", buf)
#define RPMSENSE_SENSEMASK
Definition: rpmevr.h:76
static int xisalnum(int c)
Definition: rpmiotypes.h:440
int rc
Definition: poptALL.c:670
The Header data structure.
enum rpmTag_e rpmTag
Definition: rpmtag.h:468
Header sourceHeader
Definition: rpmspec.h:171
struct EVR_s * EVR_t
Definition: rpmevr.h:22
Header h
Definition: spec.c:739
int addReqProv(Spec spec, Header h, rpmTag tagN, const char *N, const char *EVR, rpmsenseFlags Flags, rpmuint32_t index)
Add dependency to header, filtering duplicates.
Definition: reqprov.c:14
rpmsenseFlags rpmEVRflags(const char *op, const char **end)
Return comparison operator sense flags.
Definition: rpmevr.c:406
int rpmEVRparse(const char *evrstr, EVR_t evr)
Split EVR string into epoch, version, and release components.
Definition: rpmevr.c:181
#define SKIPWHITE(_x)
Definition: parseReqs.c:17
const char * N
Definition: rpmds.c:2714
char * alloca()
enum rpmRC_e rpmRC
RPM return codes.
Definition: signature.c:616
Yet Another syslog(3) API clone.
goto exit
Definition: db3.c:1903
memset(_r, 0, sizeof(*_r))
Header header
Definition: rpmspec.h:217
unsigned int rpmuint32_t
Definition: rpmiotypes.h:28
int ix
Definition: rpmps-py.c:174
size_t nr
Definition: rpmmtree.c:526
char * line
Definition: rpmspec.h:138
enum evrFlags_e rpmsenseFlags
Definition: rpmevr.h:74
The structure used to store values parsed from a spec file.
Definition: rpmspec.h:113
char * t
Definition: rpmds.c:2716
This is the only module users of librpmbuild should need to include.
int lineNum
Definition: rpmspec.h:139
return NULL
Definition: poptALL.c:613
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
Definition: spec.c:737
#define SKIPNONWHITE(_x)
Definition: parseReqs.c:18
#define _(Text)
Definition: system.h:29
rpmRC parseRCPOT(Spec spec, Package pkg, const char *field, rpmTag tagN, rpmuint32_t index, rpmsenseFlags tagflags)
Parse dependency relations from spec file and/or autogenerated output buffer.
Definition: parseReqs.c:20
The structure used to store values for a package.
Definition: rpmspec.h:214
#define xmalloc
Definition: system.h:32
char * EVR
Definition: rpmds.c:2715
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:647
evrFlags Flags
Definition: rpmds.c:2717
strncpy(sbuf, f, flen)
Spec spec
Definition: spec-py.c:121