"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/UriCommon.c" between
uriparser-0.9.4.tar.xz and uriparser-0.9.5.tar.xz

About: uriparser is a strictly RFC 3986 compliant URI parsing library (with Unicode support).

UriCommon.c  (uriparser-0.9.4.tar.xz):UriCommon.c  (uriparser-0.9.5.tar.xz)
skipping to change at line 112 skipping to change at line 112
if (diff > 0) { if (diff > 0) {
return 1; return 1;
} else if (diff < 0) { } else if (diff < 0) {
return -1; return -1;
} }
return diff; return diff;
} }
/* Properly removes "." and ".." path segments */
UriBool URI_FUNC(RemoveDotSegments)(URI_TYPE(Uri) * uri,
UriBool relative, UriMemoryManager * memory) {
if (uri == NULL) {
return URI_TRUE;
}
return URI_FUNC(RemoveDotSegmentsEx)(uri, relative, uri->owner, memory);
}
UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri,
UriBool relative, UriBool pathOwned, UriMemoryManager * memory) { UriBool relative, UriBool pathOwned, UriMemoryManager * memory) {
URI_TYPE(PathSegment) * walker; URI_TYPE(PathSegment) * walker;
if ((uri == NULL) || (uri->pathHead == NULL)) { if ((uri == NULL) || (uri->pathHead == NULL)) {
return URI_TRUE; return URI_TRUE;
} }
walker = uri->pathHead; walker = uri->pathHead;
walker->reserved = NULL; /* Prev pointer */ walker->reserved = NULL; /* Prev pointer */
do { do {
UriBool removeSegment = URI_FALSE; UriBool removeSegment = URI_FALSE;
int len = (int)(walker->text.afterLast - walker->text.first); int len = (int)(walker->text.afterLast - walker->text.first);
switch (len) { switch (len) {
case 1: case 1:
if ((walker->text.first)[0] == _UT('.')) { if ((walker->text.first)[0] == _UT('.')) {
/* "." segment -> remove if not essential */ /* "." segment -> remove if not essential */
URI_TYPE(PathSegment) * const prev = walker->rese rved; URI_TYPE(PathSegment) * const prev = walker->rese rved;
URI_TYPE(PathSegment) * const nextBackup = walker ->next; URI_TYPE(PathSegment) * const nextBackup = walker ->next;
/* Is this dot segment essential? */ /*
* Is this dot segment essential,
* i.e. is there a chance of changing semantics b
y dropping this dot segment?
*
* For example, changing "./http://foo" into "htt
p://foo" would change semantics
* and hence the dot segment is essential to that
case and cannot be removed.
*/
removeSegment = URI_TRUE; removeSegment = URI_TRUE;
if (relative && (walker == uri->pathHead) && (wal ker->next != NULL)) { if (relative && (walker == uri->pathHead) && (wal ker->next != NULL)) {
const URI_CHAR * ch = walker->next->text. first; const URI_CHAR * ch = walker->next->text. first;
for (; ch < walker->next->text.afterLast; ch++) { for (; ch < walker->next->text.afterLast; ch++) {
if (*ch == _UT(':')) { if (*ch == _UT(':')) {
removeSegment = URI_FALSE ; removeSegment = URI_FALSE ;
break; break;
} }
} }
} }
if (removeSegment) { if (removeSegment) {
/* .. then let's go remove that segment. */
/* Last segment? */ /* Last segment? */
if (walker->next != NULL) { if (walker->next != NULL) {
/* Not last segment */ /* Not last segment, i.e. first o
r middle segment
* OLD: (prev|NULL) <- walker <-
next
* NEW: (prev|NULL) <-----------
next */
walker->next->reserved = prev; walker->next->reserved = prev;
if (prev == NULL) { if (prev == NULL) {
/* First but not last seg /* First but not last seg
ment */ ment
* OLD: head -> walker ->
next
* NEW: head ----------->
next */
uri->pathHead = walker->n ext; uri->pathHead = walker->n ext;
} else { } else {
/* Middle segment */ /* Middle segment
* OLD: prev -> walker ->
next
* NEW: prev ----------->
next */
prev->next = walker->next ; prev->next = walker->next ;
} }
if (pathOwned && (walker->text.fi rst != walker->text.afterLast)) { if (pathOwned && (walker->text.fi rst != walker->text.afterLast)) {
memory->free(memory, (URI _CHAR *)walker->text.first); memory->free(memory, (URI _CHAR *)walker->text.first);
} }
memory->free(memory, walker); memory->free(memory, walker);
} else { } else {
/* Last segment */ /* Last segment */
if (pathOwned && (walker->text.fi rst != walker->text.afterLast)) { if (pathOwned && (walker->text.fi rst != walker->text.afterLast)) {
skipping to change at line 211 skipping to change at line 215
if (((walker->text.first)[0] == _UT('.')) if (((walker->text.first)[0] == _UT('.'))
&& ((walker->text.first)[1] == _UT('.'))) { && ((walker->text.first)[1] == _UT('.'))) {
/* Path ".." -> remove this and the previous segm ent */ /* Path ".." -> remove this and the previous segm ent */
URI_TYPE(PathSegment) * const prev = walker->rese rved; URI_TYPE(PathSegment) * const prev = walker->rese rved;
URI_TYPE(PathSegment) * prevPrev; URI_TYPE(PathSegment) * prevPrev;
URI_TYPE(PathSegment) * const nextBackup = walker ->next; URI_TYPE(PathSegment) * const nextBackup = walker ->next;
removeSegment = URI_TRUE; removeSegment = URI_TRUE;
if (relative) { if (relative) {
if (prev == NULL) { if (prev == NULL) {
/* We cannot remove traversal bey
ond because the
* URI is relative and may be res
olved later.
* So we can simplify "a/../b/d"
to "b/d" but
* we cannot simplify "../b/d" (o
utside of reference resolution). */
removeSegment = URI_FALSE; removeSegment = URI_FALSE;
} else if ((prev != NULL) } else if ((prev != NULL)
&& ((prev->text.afterLast - prev->text.first) == 2) && ((prev->text.afterLast - prev->text.first) == 2)
&& ((prev->text.first)[0] == _UT('.')) && ((prev->text.first)[0] == _UT('.'))
&& ((prev->text.first)[1] == _UT('.'))) { && ((prev->text.first)[1] == _UT('.'))) {
/* We need to protect against mis -simplifying "a/../../b" to "a/b". */
removeSegment = URI_FALSE; removeSegment = URI_FALSE;
} }
} }
if (removeSegment) { if (removeSegment) {
if (prev != NULL) { if (prev != NULL) {
/* Not first segment */ /* Not first segment */
prevPrev = prev->reserved; prevPrev = prev->reserved;
if (prevPrev != NULL) { if (prevPrev != NULL) {
/* Not even prev is the f /* Not even prev is the f
irst one */ irst one
* OLD: prevPrev -> prev
-> walker -> (next|NULL)
* NEW: prevPrev --------
-----------> (next|NULL) */
prevPrev->next = walker-> next; prevPrev->next = walker-> next;
if (walker->next != NULL) { if (walker->next != NULL) {
/* Update parent
relationship as well
* OLD: prevPrev
<- prev <- walker <- next
* NEW: prevPrev
<------------------- next */
walker->next->res erved = prevPrev; walker->next->res erved = prevPrev;
} else { } else {
/* Last segment - > insert "" segment to represent trailing slash, update tail */ /* Last segment - > insert "" segment to represent trailing slash, update tail */
URI_TYPE(PathSegm ent) * const segment = memory->calloc(memory, 1, sizeof(URI_TYPE(PathSegment))); URI_TYPE(PathSegm ent) * const segment = memory->calloc(memory, 1, sizeof(URI_TYPE(PathSegment)));
if (segment == NU LL) { if (segment == NU LL) {
if (pathO wned && (walker->text.first != walker->text.afterLast)) { if (pathO wned && (walker->text.first != walker->text.afterLast)) {
m emory->free(memory, (URI_CHAR *)walker->text.first); m emory->free(memory, (URI_CHAR *)walker->text.first);
} }
memory->f ree(memory, walker); memory->f ree(memory, walker);
skipping to change at line 293 skipping to change at line 307
if (pathOwned && (prev->t ext.first != prev->text.afterLast)) { if (pathOwned && (prev->t ext.first != prev->text.afterLast)) {
memory->free(memo ry, (URI_CHAR *)prev->text.first); memory->free(memo ry, (URI_CHAR *)prev->text.first);
} }
memory->free(memory, prev ); memory->free(memory, prev );
walker = nextBackup; walker = nextBackup;
} }
} else { } else {
URI_TYPE(PathSegment) * const ano therNextBackup = walker->next; URI_TYPE(PathSegment) * const ano therNextBackup = walker->next;
/* First segment -> update head p int freeWalker = URI_TRUE;
ointer */
uri->pathHead = walker->next; /* First segment */
if (walker->next != NULL) { if (walker->next != NULL) {
/* First segment of multi
ple -> update head
* OLD: head -> walker ->
next
* NEW: head ----------->
next */
uri->pathHead = walker->n
ext;
/* Update parent link as
well
* OLD: head <- walker <-
next
* NEW: head <-----------
next */
walker->next->reserved = NULL; walker->next->reserved = NULL;
} else { } else {
/* Last segment -> update if (uri->absolutePath) {
tail */ /* First and only
uri->pathTail = NULL; segment -> update head
* OLD: head -> w
alker -> NULL
* NEW: head ----
-------> NULL */
uri->pathHead = N
ULL;
/* Last segment -
> update tail
* OLD: tail -> w
alker
* NEW: tail -> N
ULL */
uri->pathTail = N
ULL;
} else {
/* Re-use segment
for "" path segment to represent trailing slash,
* then update he
ad and tail */
if (pathOwned &&
(walker->text.first != walker->text.afterLast)) {
memory->f
ree(memory, (URI_CHAR *)walker->text.first);
}
walker->text.firs
t = URI_FUNC(SafeToPointTo);
walker->text.afte
rLast = URI_FUNC(SafeToPointTo);
freeWalker = URI_
FALSE;
}
} }
if (pathOwned && (walker->text.fi if (freeWalker) {
rst != walker->text.afterLast)) { if (pathOwned && (walker-
memory->free(memory, (URI >text.first != walker->text.afterLast)) {
_CHAR *)walker->text.first); memory->free(memo
ry, (URI_CHAR *)walker->text.first);
}
memory->free(memory, walk
er);
} }
memory->free(memory, walker);
walker = anotherNextBackup; walker = anotherNextBackup;
} }
} }
} }
break; break;
} /* end of switch */
}
if (!removeSegment) { if (!removeSegment) {
/* .. then let's move to the next element, and start agai n. */
if (walker->next != NULL) { if (walker->next != NULL) {
walker->next->reserved = walker; walker->next->reserved = walker;
} else { } else {
/* Last segment -> update tail */ /* Last segment -> update tail */
uri->pathTail = walker; uri->pathTail = walker;
} }
walker = walker->next; walker = walker->next;
} }
} while (walker != NULL); } while (walker != NULL);
return URI_TRUE; return URI_TRUE;
} }
/* Properly removes "." and ".." path segments */ /* Properly removes "." and ".." path segments */
UriBool URI_FUNC(RemoveDotSegmentsAbsolute)(URI_TYPE(Uri) * uri, UriBool URI_FUNC(RemoveDotSegmentsAbsolute)(URI_TYPE(Uri) * uri,
UriMemoryManager * memory) { UriMemoryManager * memory) {
const UriBool ABSOLUTE = URI_FALSE; const UriBool ABSOLUTE = URI_FALSE;
return URI_FUNC(RemoveDotSegments)(uri, ABSOLUTE, memory); if (uri == NULL) {
return URI_TRUE;
}
return URI_FUNC(RemoveDotSegmentsEx)(uri, ABSOLUTE, uri->owner, memory);
} }
unsigned char URI_FUNC(HexdigToInt)(URI_CHAR hexdig) { unsigned char URI_FUNC(HexdigToInt)(URI_CHAR hexdig) {
switch (hexdig) { switch (hexdig) {
case _UT('0'): case _UT('0'):
case _UT('1'): case _UT('1'):
case _UT('2'): case _UT('2'):
case _UT('3'): case _UT('3'):
case _UT('4'): case _UT('4'):
case _UT('5'): case _UT('5'):
 End of changes. 18 change blocks. 
30 lines changed or deleted 116 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)