~ubuntu-branches/ubuntu/raring/reprepro/raring

« back to all changes in this revision

Viewing changes to changes.c

  • Committer: Bazaar Package Importer
  • Author(s): Bernhard R. Link
  • Date: 2011-05-05 16:34:23 UTC
  • mfrom: (21.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110505163423-x49kbdijyoubai4x
Tags: 4.6.0-1
* new release
- general cleanup
- new FilterSrcList
* increase Standards-Version, no changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
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) {
33
33
 
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;
41
41
        filetype type;
42
42
        char *section, *priority, *basefilename, *name;
45
45
        bool checkfilename = false;
46
46
 
47
47
        p = fileline;
48
 
        while( *p !='\0' && xisspace(*p) )
 
48
        while (*p !='\0' && xisspace(*p))
49
49
                p++;
50
50
        md5start = p;
51
 
        while( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') )
 
51
        while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f'))
52
52
                p++;
53
 
        if( *p == '\0' ) {
54
 
                fprintf(stderr,"Missing md5sum in '%s'!\n", fileline);
 
53
        if (*p == '\0') {
 
54
                fprintf(stderr, "Missing md5sum in '%s'!\n", fileline);
55
55
                return RET_ERROR;
56
56
        }
57
 
        if( !xisspace(*p) ) {
58
 
                fprintf(stderr,"Malformed md5 hash in '%s'!\n", fileline);
 
57
        if (!xisspace(*p)) {
 
58
                fprintf(stderr, "Malformed md5 hash in '%s'!\n", fileline);
59
59
                return RET_ERROR;
60
60
        }
61
61
        md5end = p;
62
 
        while( *p !='\0' && xisspace(*p) )
 
62
        while (*p !='\0' && xisspace(*p))
63
63
                p++;
64
 
        while( *p == '0' && p[1] >= '0' && p[1] <= '9' )
 
64
        while (*p == '0' && p[1] >= '0' && p[1] <= '9')
65
65
                p++;
66
66
        sizestart = p;
67
 
        while( *p >= '0' && *p <= '9' )
 
67
        while (*p >= '0' && *p <= '9')
68
68
                p++;
69
 
        if( *p == '\0' ) {
70
 
                fprintf(stderr,"Missing size (second argument) in '%s'!\n", fileline);
 
69
        if (*p == '\0') {
 
70
                fprintf(stderr,
 
71
"Missing size (second argument) in '%s'!\n", fileline);
71
72
                return RET_ERROR;
72
73
        }
73
 
        if( !xisspace(*p) ) {
74
 
                fprintf(stderr,"Malformed size (second argument) in '%s'!\n", fileline);
 
74
        if (!xisspace(*p)) {
 
75
                fprintf(stderr,
 
76
"Malformed size (second argument) in '%s'!\n", fileline);
75
77
                return RET_ERROR;
76
78
        }
77
79
        sizeend = p;
78
 
        while( *p !='\0' && xisspace(*p) )
 
80
        while (*p !='\0' && xisspace(*p))
79
81
                p++;
80
82
        sectionstart = p;
81
 
        while( *p !='\0' && !xisspace(*p) )
 
83
        while (*p !='\0' && !xisspace(*p))
82
84
                p++;
83
85
        sectionend = p;
84
 
        while( *p !='\0' && xisspace(*p) )
 
86
        while (*p !='\0' && xisspace(*p))
85
87
                p++;
86
88
        priostart = p;
87
 
        while( *p !='\0' && !xisspace(*p) )
 
89
        while (*p !='\0' && !xisspace(*p))
88
90
                p++;
89
91
        prioend = p;
90
 
        while( *p !='\0' && xisspace(*p) )
 
92
        while (*p !='\0' && xisspace(*p))
91
93
                p++;
92
94
        filestart = p;
93
 
        while( *p !='\0' && !xisspace(*p) )
 
95
        while (*p !='\0' && !xisspace(*p))
94
96
                p++;
95
97
        fileend = p;
96
 
        while( *p !='\0' && xisspace(*p) )
 
98
        while (*p !='\0' && xisspace(*p))
97
99
                p++;
98
 
        if( *p != '\0' ) {
99
 
                fprintf(stderr,"Unexpected sixth argument in '%s'!\n",fileline);
 
100
        if (*p != '\0') {
 
101
                fprintf(stderr,
 
102
"Unexpected sixth argument in '%s'!\n", fileline);
100
103
                return RET_ERROR;
101
104
        }
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') {
 
107
                fprintf(stderr,
 
108
"Wrong number of arguments in '%s' (5 expected)!\n",
105
109
                                fileline);
106
110
                return RET_ERROR;
107
111
        }
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;
132
136
        }
133
137
 
134
138
        p = filestart;
135
 
        while( *p != '\0' && *p != '_' && !xisspace(*p) )
 
139
        while (*p != '\0' && *p != '_' && !xisspace(*p))
136
140
                p++;
137
 
        if( *p != '_' ) {
138
 
                if( *p == '\0' )
139
 
                        fprintf(stderr, "No underscore found in file name in '%s'!\n",
 
141
        if (*p != '_') {
 
142
                if (*p == '\0')
 
143
                        fprintf(stderr,
 
144
"No underscore found in file name in '%s'!\n",
140
145
                                        fileline);
141
146
                else
142
 
                        fprintf(stderr, "Unexpected character '%c' in file name in '%s'!\n",
 
147
                        fprintf(stderr,
 
148
"Unexpected character '%c' in file name in '%s'!\n",
143
149
                                        *p, fileline);
144
150
                return RET_ERROR;
145
151
        }
150
156
        /* changing 3.0 format to now also allow _ in source files
151
157
         * makes this parsing quite more ugly... */
152
158
 
153
 
        while( *p !='\0' && !xisspace(*p) )
 
159
        while (*p !='\0' && !xisspace(*p))
154
160
                p++;
155
161
        l = p - versionstart;
156
162
 
157
163
        /* identify the binary types (they have no compression
158
164
         * and will need a _ */
159
165
 
160
 
        if( l >= 4 && memcmp(p-4, ".deb", 4) == 0 )
 
166
        if (l >= 4 && memcmp(p-4, ".deb", 4) == 0)
161
167
                type = fe_DEB;
162
 
        else if( l >= 5 && memcmp(p-5, ".udeb", 5) == 0 )
 
168
        else if (l >= 5 && memcmp(p-5, ".udeb", 5) == 0)
163
169
                type = fe_UDEB;
164
170
        else
165
171
                type = fe_UNKNOWN;
166
172
 
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",
173
 
                                        *p, fileline);
 
177
                if (*p != '\0' && *p != '_') {
 
178
                        fprintf(stderr,
 
179
"Unexpected character '%c' in file name within '%s'!\n", *p, fileline);
174
180
                        return RET_ERROR;
175
181
                }
176
 
                if( *p != '_' ) {
177
 
                        fprintf(stderr, "Cannot cope with .[u]deb filename not containing an underscore (in '%s')!", fileline);
 
182
                if (*p != '_') {
 
183
                        fprintf(stderr,
 
184
"Cannot cope with .[u]deb filename not containing an underscore (in '%s')!",
 
185
                                        fileline);
178
186
                        return RET_ERROR;
179
187
                }
180
188
                p++;
181
189
                archstart = p;
182
 
                if( type == fe_DEB )
 
190
                if (type == fe_DEB)
183
191
                        archend = versionstart + l - 4;
184
192
                else {
185
 
                        assert( type == fe_UDEB );
 
193
                        assert (type == fe_UDEB);
186
194
                        archend = versionstart + l - 5;
187
195
                }
188
 
                if( archend - archstart == 6 &&
189
 
                                strncmp(archstart,"source",6) == 0 ) {
 
196
                if (archend - archstart == 6 &&
 
197
                                strncmp(archstart, "source", 6) == 0) {
190
198
                        fprintf(stderr,
191
199
"Architecture 'source' not allowed for .[u]debs ('%s')!\n", filestart);
192
200
                        return RET_ERROR;
207
215
 
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) {
211
219
                        type = fe_ORIG;
212
220
                        eoi = p - 9;
213
 
                } else if( l > 4 && strncmp(p-4, ".tar", 4) == 0 ) {
 
221
                } else if (l > 4 && strncmp(p-4, ".tar", 4) == 0) {
214
222
                        type = fe_TAR;
215
223
                        eoi = p - 4;
216
 
                } else if( l > 5 && strncmp(p-5,".diff", 5) == 0 ) {
 
224
                } else if (l > 5 && strncmp(p-5, ".diff", 5) == 0) {
217
225
                        type = fe_DIFF;
218
226
                        eoi = p - 5;
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
 
228
                                && c == c_none) {
220
229
                        type = fe_DSC;
221
230
                        eoi = p - 4;
222
 
                } else if( l > 4 && strncmp(p-4, ".log", 4) == 0 ) {
 
231
                } else if (l > 4 && strncmp(p-4, ".log", 4) == 0) {
223
232
                        type = fe_LOG;
224
233
                        eoi = p - 4;
225
 
                } else if( l > 6 && strncmp(p-6, ".build", 6) == 0 ) {
 
234
                } else if (l > 6 && strncmp(p-6, ".build", 6) == 0) {
226
235
                        type = fe_LOG;
227
236
                        eoi = p - 6;
228
237
                }
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);
233
 
                        if( p >= eoi ) {
 
242
                        if (p >= eoi) {
234
243
                                /* all well */
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-");
243
252
                                        return RET_ERROR;
244
253
                                }
245
254
                                checkfilename = true;
246
 
                        } else if( type == fe_LOG ) {
247
 
                                if( *p == '_' ) {
 
255
                        } else if (type == fe_LOG) {
 
256
                                if (*p == '_') {
248
257
                                        archstart = p + 1;
249
258
                                        archend = eoi;
250
259
                                        checkfilename = true;
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;
282
291
        }
283
 
        if( checkfilename || !atom_defined(architecture)) {
 
292
        if (checkfilename || !atom_defined(architecture)) {
284
293
                retvalue r;
285
294
 
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 );
 
299
                if (!RET_IS_OK(r)) {
 
300
                        assert (r != RET_NOTHING);
292
301
                        free(section); free(priority);
293
302
                        free(basefilename); free(name);
294
303
                        return r;