32
32
retvalue changes_parsefileline(const char *fileline, /*@out@*/filetype *result_type, /*@out@*/char **result_basename, /*@out@*/struct hash_data *hash_p, /*@out@*/struct hash_data *size_p, /*@out@*/char **result_section, /*@out@*/char **result_priority, /*@out@*/architecture_t *result_architecture, /*@out@*/char **result_name) {
34
const char *p,*md5start,*md5end;
35
const char *sizestart,*sizeend;
36
const char *sectionstart,*sectionend;
37
const char *priostart,*prioend;
38
const char *filestart,*nameend,*fileend;
39
const char *archstart,*archend;
34
const char *p, *md5start, *md5end;
35
const char *sizestart, *sizeend;
36
const char *sectionstart, *sectionend;
37
const char *priostart, *prioend;
38
const char *filestart, *nameend, *fileend;
39
const char *archstart, *archend;
40
40
const char *versionstart;
42
42
char *section, *priority, *basefilename, *name;
45
45
bool checkfilename = false;
48
while( *p !='\0' && xisspace(*p) )
48
while (*p !='\0' && xisspace(*p))
51
while( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') )
51
while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f'))
54
fprintf(stderr,"Missing md5sum in '%s'!\n", fileline);
54
fprintf(stderr, "Missing md5sum in '%s'!\n", fileline);
58
fprintf(stderr,"Malformed md5 hash in '%s'!\n", fileline);
58
fprintf(stderr, "Malformed md5 hash in '%s'!\n", fileline);
62
while( *p !='\0' && xisspace(*p) )
62
while (*p !='\0' && xisspace(*p))
64
while( *p == '0' && p[1] >= '0' && p[1] <= '9' )
64
while (*p == '0' && p[1] >= '0' && p[1] <= '9')
67
while( *p >= '0' && *p <= '9' )
67
while (*p >= '0' && *p <= '9')
70
fprintf(stderr,"Missing size (second argument) in '%s'!\n", fileline);
71
"Missing size (second argument) in '%s'!\n", fileline);
74
fprintf(stderr,"Malformed size (second argument) in '%s'!\n", fileline);
76
"Malformed size (second argument) in '%s'!\n", fileline);
78
while( *p !='\0' && xisspace(*p) )
80
while (*p !='\0' && xisspace(*p))
81
while( *p !='\0' && !xisspace(*p) )
83
while (*p !='\0' && !xisspace(*p))
84
while( *p !='\0' && xisspace(*p) )
86
while (*p !='\0' && xisspace(*p))
87
while( *p !='\0' && !xisspace(*p) )
89
while (*p !='\0' && !xisspace(*p))
90
while( *p !='\0' && xisspace(*p) )
92
while (*p !='\0' && xisspace(*p))
93
while( *p !='\0' && !xisspace(*p) )
95
while (*p !='\0' && !xisspace(*p))
96
while( *p !='\0' && xisspace(*p) )
98
while (*p !='\0' && xisspace(*p))
99
fprintf(stderr,"Unexpected sixth argument in '%s'!\n",fileline);
102
"Unexpected sixth argument in '%s'!\n", fileline);
100
103
return RET_ERROR;
102
if( *md5start == '\0' || *sizestart == '\0' || *sectionstart == '\0'
103
|| *priostart == '\0' || *filestart == '\0' ) {
104
fprintf(stderr, "Wrong number of arguments in '%s' (5 expected)!\n",
105
if (*md5start == '\0' || *sizestart == '\0' || *sectionstart == '\0'
106
|| *priostart == '\0' || *filestart == '\0') {
108
"Wrong number of arguments in '%s' (5 expected)!\n",
106
110
return RET_ERROR;
108
if( (sectionend - sectionstart == 6 &&
112
if ((sectionend - sectionstart == 6 &&
109
113
strncmp(sectionstart, "byhand", 6) == 0) ||
110
114
(sectionend - sectionstart > 4 &&
111
115
strncmp(sectionstart, "raw-", 4) == 0)) {
112
116
section = strndup(sectionstart, sectionend - sectionstart);
113
117
priority = strndup(priostart, prioend - priostart);
114
118
basefilename = strndup(filestart, fileend - filestart);
115
if( FAILEDTOALLOC(section) || FAILEDTOALLOC(priority) ||
116
FAILEDTOALLOC(basefilename) ) {
119
if (FAILEDTOALLOC(section) || FAILEDTOALLOC(priority) ||
120
FAILEDTOALLOC(basefilename)) {
117
121
free(section); free(priority);
118
122
free(basefilename);
119
123
return RET_ERROR_OOM;
150
156
/* changing 3.0 format to now also allow _ in source files
151
157
* makes this parsing quite more ugly... */
153
while( *p !='\0' && !xisspace(*p) )
159
while (*p !='\0' && !xisspace(*p))
155
161
l = p - versionstart;
157
163
/* identify the binary types (they have no compression
158
164
* and will need a _ */
160
if( l >= 4 && memcmp(p-4, ".deb", 4) == 0 )
166
if (l >= 4 && memcmp(p-4, ".deb", 4) == 0)
162
else if( l >= 5 && memcmp(p-5, ".udeb", 5) == 0 )
168
else if (l >= 5 && memcmp(p-5, ".udeb", 5) == 0)
165
171
type = fe_UNKNOWN;
167
if( type != fe_UNKNOWN ) {
173
if (type != fe_UNKNOWN) {
168
174
/* a _ should separate the version from the rest */
169
175
p = versionstart;
170
176
names_overversion(&p, true);
171
if( *p != '\0' && *p != '_' ) {
172
fprintf(stderr, "Unexpected character '%c' in file name within '%s'!\n",
177
if (*p != '\0' && *p != '_') {
179
"Unexpected character '%c' in file name within '%s'!\n", *p, fileline);
174
180
return RET_ERROR;
177
fprintf(stderr, "Cannot cope with .[u]deb filename not containing an underscore (in '%s')!", fileline);
184
"Cannot cope with .[u]deb filename not containing an underscore (in '%s')!",
178
186
return RET_ERROR;
183
191
archend = versionstart + l - 4;
185
assert( type == fe_UDEB );
193
assert (type == fe_UDEB);
186
194
archend = versionstart + l - 5;
188
if( archend - archstart == 6 &&
189
strncmp(archstart,"source",6) == 0 ) {
196
if (archend - archstart == 6 &&
197
strncmp(archstart, "source", 6) == 0) {
191
199
"Architecture 'source' not allowed for .[u]debs ('%s')!\n", filestart);
192
200
return RET_ERROR;
208
216
archstart = "source";
209
217
archend = archstart + 6;
210
if( l > 9 && strncmp(p-9, ".orig.tar", 9) == 0 ) {
218
if (l > 9 && strncmp(p-9, ".orig.tar", 9) == 0) {
213
} else if( l > 4 && strncmp(p-4, ".tar", 4) == 0 ) {
221
} else if (l > 4 && strncmp(p-4, ".tar", 4) == 0) {
216
} else if( l > 5 && strncmp(p-5,".diff", 5) == 0 ) {
224
} else if (l > 5 && strncmp(p-5, ".diff", 5) == 0) {
219
} else if( l > 4 && strncmp(p-4,".dsc",4) == 0 && c == c_none ) {
227
} else if (l > 4 && strncmp(p-4, ".dsc", 4) == 0
222
} else if( l > 4 && strncmp(p-4, ".log", 4) == 0 ) {
231
} else if (l > 4 && strncmp(p-4, ".log", 4) == 0) {
225
} else if( l > 6 && strncmp(p-6, ".build", 6) == 0 ) {
234
} else if (l > 6 && strncmp(p-6, ".build", 6) == 0) {
229
if( type != fe_UNKNOWN ) {
238
if (type != fe_UNKNOWN) {
230
239
/* check for a proper version */
231
240
p = versionstart;
232
241
names_overversion(&p, true);
235
} else if( type == fe_TAR ) {
244
} else if (type == fe_TAR) {
236
245
/* a tar might be a component with ugly
237
246
* data between .orig- and the .tar.c */
238
247
const char *o = strstr(versionstart, ".orig-");
274
283
// list multiple..
275
284
architecture = architecture_find_l(archstart, archend - archstart);
276
285
name = strndup(filestart, nameend - filestart);
277
if( FAILEDTOALLOC(section) || FAILEDTOALLOC(priority) ||
278
FAILEDTOALLOC(basefilename) || FAILEDTOALLOC(name) ) {
286
if (FAILEDTOALLOC(section) || FAILEDTOALLOC(priority) ||
287
FAILEDTOALLOC(basefilename) || FAILEDTOALLOC(name)) {
279
288
free(section); free(priority);
280
289
free(basefilename); free(name);
281
290
return RET_ERROR_OOM;
283
if( checkfilename || !atom_defined(architecture)) {
292
if (checkfilename || !atom_defined(architecture)) {
286
295
/* as we no longer run properversion over the whole
287
296
* rest of the string, at least make sure nothing evil
288
297
* is in this name */
289
298
r = properfilename(basefilename);
290
if( !RET_IS_OK(r) ) {
291
assert( r != RET_NOTHING );
300
assert (r != RET_NOTHING);
292
301
free(section); free(priority);
293
302
free(basefilename); free(name);