~ubuntu-branches/ubuntu/precise/sitecopy/precise

« back to all changes in this revision

Viewing changes to lib/neon/ne_uri.c

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2008-07-22 07:31:05 UTC
  • mfrom: (1.1.4 upstream) (4.1.7 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080722073105-cbqs1hnc2wvqejfd
Tags: 1:0.16.6-1
* New upstream release
  - fix a crash with progress bar enabled; Closes: #486378
* debian/control
  - set myself as maintainer, Kartik as uploader
  - set Vcs-{Browser,Git} fields
  - bump Standards-Version to 3.8.0
    + debian/README.source added
  - added DM-Upload-Allowed flag
* debian/patches/05_libneon27_transition.dpatch
  - removed since merged upstream
* debian/copyrightdebian/copyright
  - updated upstream email and copyright years
* debian/patches/10_bts410703_preserve_storage_files_sigint.dpatch
  - added to preserve storage files if SIGINT (Ctrl+C) is sent to sitecopy;
    thanks to Andreas Henriksson for the patch; Closes: #410703

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
#define URI_PCHAR (URI_UNRESERVED | PC | URI_SUBDELIM | CL | AT)
85
85
/* invented: segchar = pchar / "/" */
86
86
#define URI_SEGCHAR (URI_PCHAR | FS)
87
 
/* query = fragment = *( pchar / "/" / "?" ) */
 
87
/* query = *( pchar / "/" / "?" ) */
88
88
#define URI_QUERY (URI_PCHAR | FS | QU)
 
89
/* fragment == query */
 
90
#define URI_FRAGMENT URI_QUERY
89
91
 
90
92
/* any characters which should be path-escaped: */
91
93
#define URI_ESCAPE ((URI_GENDELIM & ~(FS)) | URI_SUBDELIM | OT | PC)
110
112
/*   Fx */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT
111
113
};
112
114
 
113
 
#define uri_lookup(ch) (uri_chars[(unsigned)ch])
 
115
#define uri_lookup(ch) (uri_chars[(unsigned char)ch])
114
116
 
115
117
char *ne_path_parent(const char *uri) 
116
118
{
153
155
 
154
156
    p = s = uri;
155
157
 
 
158
    /* => s = p = URI-reference */
 
159
 
156
160
    if (uri_lookup(*p) & URI_ALPHA) {
157
161
        while (uri_lookup(*p) & URI_SCHEME)
158
162
            p++;
163
167
        }
164
168
    }
165
169
 
 
170
    /* => s = heir-part, or s = relative-part */
 
171
 
166
172
    if (s[0] == '/' && s[1] == '/') {
167
173
        const char *pa;
168
174
 
169
 
        /* hier-part = "//" authority path-abempty 
170
 
         * authority = [ userinfo "@" ] host [ ":" port ] */
 
175
        /* => s = "//" authority path-abempty (from expansion of
 
176
         * either heir-part of relative-part)  */
 
177
        
 
178
        /* authority = [ userinfo "@" ] host [ ":" port ] */
171
179
 
172
180
        s = pa = s + 2; /* => s = authority */
173
181
 
218
226
        if (*s == '\0') {
219
227
            s = "/"; /* FIXME: scheme-specific. */
220
228
        }
221
 
    } 
222
 
    /* else, the path begins at s */
 
229
    }
 
230
 
 
231
    /* => s = path-abempty / path-absolute / path-rootless
 
232
     *      / path-empty / path-noscheme */
223
233
 
224
234
    p = s;
225
235
 
226
236
    while (uri_lookup(*p) & URI_SEGCHAR)
227
237
        p++;
228
238
 
 
239
    /* => p = [ "?" query ] [ "#" fragment ] */
 
240
 
229
241
    parsed->path = ne_strndup(s, p - s);
230
242
 
231
243
    if (*p != '\0') {
234
246
        while (uri_lookup(*p) & URI_QUERY)
235
247
            p++;
236
248
 
 
249
        /* => p = [ "#" fragment ] */
 
250
        /* => s = [ "?" query ] [ "#" fragment ] */
 
251
 
237
252
        if (*s == '?') {
238
253
            parsed->query = ne_strndup(s + 1, p - s - 1);
239
254
            
240
255
            if (*p != '\0') {
241
256
                s = p++;
242
257
 
243
 
                while (uri_lookup(*p) & URI_QUERY)
 
258
                while (uri_lookup(*p) & URI_FRAGMENT)
244
259
                    p++;
245
260
            }
246
261
        }
247
 
        /* p must now point to the end of the input string */
 
262
 
 
263
        /* => p now points to the next character after the
 
264
         * URI-reference; which should be the NUL byte. */
248
265
 
249
266
        if (*s == '#') {
250
267
            parsed->fragment = ne_strndup(s + 1, p - s - 1);
436
453
char *ne_path_unescape(const char *uri) 
437
454
{
438
455
    const char *pnt;
439
 
    char *ret, *retpos, buf[5] = { "0x00\0" };
 
456
    char *ret, *retpos, buf[5] = { "0x00" };
440
457
    retpos = ret = ne_malloc(strlen(uri) + 1);
441
458
    for (pnt = uri; *pnt != '\0'; pnt++) {
442
459
        if (*pnt == '%') {
523
540
#undef CASECMP
524
541
#undef CMPWITH
525
542
 
526
 
#ifndef WIN32
527
 
#undef min
528
 
#define min(a,b) ((a)<(b)?(a):(b))
529
 
#endif
530
 
 
531
543
/* TODO: implement properly */
532
544
int ne_path_compare(const char *a, const char *b) 
533
545
{
543
555
            ((traila && lena > lenb) || (trailb && lenb > lena))) {
544
556
            /* Compare them, ignoring the trailing slash on the longer
545
557
             * URI */
546
 
            if (strncasecmp(a, b, min(lena, lenb)) == 0)
 
558
            if (strncasecmp(a, b, lena < lenb ? lena : lenb) == 0)
547
559
                ret = 0;
548
560
        }
549
561
    }