hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bobhan...@apache.org
Subject [1/5] hadoop git commit: HDFS-9932: added uriparser2 library to HDFS-8707. Contributed by Bob Hansen.
Date Mon, 14 Mar 2016 15:35:54 GMT
Repository: hadoop
Updated Branches:
  refs/heads/HDFS-8707 6c19c78fa -> 775150723


http://git-wip-us.apache.org/repos/asf/hadoop/blob/196db0d6/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriRecompose.c
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriRecompose.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriRecompose.c
new file mode 100644
index 0000000..57d5a0c
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriRecompose.c
@@ -0,0 +1,573 @@
+/*
+ * uriparser - RFC 3986 URI parsing library
+ *
+ * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
+ * Copyright (C) 2007, Sebastian Pipping <webmaster@hartwork.org>
+ * All rights reserved.
+ *
+ * Redistribution  and use in source and binary forms, with or without
+ * modification,  are permitted provided that the following conditions
+ * are met:
+ *
+ *     * Redistributions   of  source  code  must  retain  the   above
+ *       copyright  notice, this list of conditions and the  following
+ *       disclaimer.
+ *
+ *     * Redistributions  in  binary  form must  reproduce  the  above
+ *       copyright  notice, this list of conditions and the  following
+ *       disclaimer   in  the  documentation  and/or  other  materials
+ *       provided with the distribution.
+ *
+ *     * Neither  the name of the <ORGANIZATION> nor the names of  its
+ *       contributors  may  be  used to endorse  or  promote  products
+ *       derived  from  this software without specific  prior  written
+ *       permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT  NOT
+ * LIMITED  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS
+ * FOR  A  PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT  SHALL  THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL,    SPECIAL,   EXEMPLARY,   OR   CONSEQUENTIAL   DAMAGES
+ * (INCLUDING,  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT  LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE  OR  OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* What encodings are enabled? */
+#include "UriDefsConfig.h"
+#if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE))
+/* Include SELF twice */
+# define URI_PASS_ANSI 1
+# include "UriRecompose.c"
+# undef URI_PASS_ANSI
+# define URI_PASS_UNICODE 1
+# include "UriRecompose.c"
+# undef URI_PASS_UNICODE
+#else
+# ifdef URI_PASS_ANSI
+#  include "UriDefsAnsi.h"
+# else
+#  include "UriDefsUnicode.h"
+#  include <wchar.h>
+# endif
+
+
+
+#ifndef URI_DOXYGEN
+# include "Uri.h"
+# include "UriCommon.h"
+#endif
+
+
+
+static int URI_FUNC(ToStringEngine)(URI_CHAR * dest, const URI_TYPE(Uri) * uri,
+		int maxChars, int * charsWritten, int * charsRequired);
+
+
+
+int URI_FUNC(ToStringCharsRequired)(const URI_TYPE(Uri) * uri,
+		int * charsRequired) {
+	const int MAX_CHARS = ((unsigned int)-1) >> 1;
+	return URI_FUNC(ToStringEngine)(NULL, uri, MAX_CHARS, NULL, charsRequired);
+}
+
+
+
+int URI_FUNC(ToString)(URI_CHAR * dest, const URI_TYPE(Uri) * uri,
+		int maxChars, int * charsWritten) {
+	return URI_FUNC(ToStringEngine)(dest, uri, maxChars, charsWritten, NULL);
+}
+
+
+
+static URI_INLINE int URI_FUNC(ToStringEngine)(URI_CHAR * dest,
+		const URI_TYPE(Uri) * uri, int maxChars, int * charsWritten,
+		int * charsRequired) {
+	int written = 0;
+	if ((uri == NULL) || ((dest == NULL) && (charsRequired == NULL))) {
+		if (charsWritten != NULL) {
+			*charsWritten = 0;
+		}
+		return URI_ERROR_NULL;
+	}
+
+	if (maxChars < 1) {
+		if (charsWritten != NULL) {
+			*charsWritten = 0;
+		}
+		return URI_ERROR_TOSTRING_TOO_LONG;
+	}
+	maxChars--; /* So we don't have to substract 1 for '\0' all the time */
+
+	/* [01/19]	result = "" */
+				if (dest != NULL) {
+					dest[0] = _UT('\0');
+				} else {
+					(*charsRequired) = 0;
+				}
+	/* [02/19]	if defined(scheme) then */
+				if (uri->scheme.first != NULL) {
+	/* [03/19]		append scheme to result; */
+					const int charsToWrite
+							= (int)(uri->scheme.afterLast - uri->scheme.first);
+					if (dest != NULL) {
+						if (written + charsToWrite <= maxChars) {
+							memcpy(dest + written, uri->scheme.first,
+									charsToWrite * sizeof(URI_CHAR));
+							written += charsToWrite;
+						} else {
+							dest[0] = _UT('\0');
+							if (charsWritten != NULL) {
+								*charsWritten = 0;
+							}
+							return URI_ERROR_TOSTRING_TOO_LONG;
+						}
+					} else {
+						(*charsRequired) += charsToWrite;
+					}
+	/* [04/19]		append ":" to result; */
+					if (dest != NULL) {
+						if (written + 1 <= maxChars) {
+							memcpy(dest + written, _UT(":"),
+									1 * sizeof(URI_CHAR));
+							written += 1;
+						} else {
+							dest[0] = _UT('\0');
+							if (charsWritten != NULL) {
+								*charsWritten = 0;
+							}
+							return URI_ERROR_TOSTRING_TOO_LONG;
+						}
+					} else {
+						(*charsRequired) += 1;
+					}
+	/* [05/19]	endif; */
+				}
+	/* [06/19]	if defined(authority) then */
+				if (URI_FUNC(IsHostSet)(uri)) {
+	/* [07/19]		append "//" to result; */
+					if (dest != NULL) {
+						if (written + 2 <= maxChars) {
+							memcpy(dest + written, _UT("//"),
+									2 * sizeof(URI_CHAR));
+							written += 2;
+						} else {
+							dest[0] = _UT('\0');
+							if (charsWritten != NULL) {
+								*charsWritten = 0;
+							}
+							return URI_ERROR_TOSTRING_TOO_LONG;
+						}
+					} else {
+						(*charsRequired) += 2;
+					}
+	/* [08/19]		append authority to result; */
+					/* UserInfo */
+					if (uri->userInfo.first != NULL) {
+						const int charsToWrite = (int)(uri->userInfo.afterLast - uri->userInfo.first);
+						if (dest != NULL) {
+							if (written + charsToWrite <= maxChars) {
+								memcpy(dest + written, uri->userInfo.first,
+										charsToWrite * sizeof(URI_CHAR));
+								written += charsToWrite;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+
+							if (written + 1 <= maxChars) {
+								memcpy(dest + written, _UT("@"),
+										1 * sizeof(URI_CHAR));
+								written += 1;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+						} else {
+							(*charsRequired) += charsToWrite + 1;
+						}
+					}
+
+					/* Host */
+					if (uri->hostData.ip4 != NULL) {
+						/* IPv4 */
+						int i = 0;
+						for (; i < 4; i++) {
+							const unsigned char value = uri->hostData.ip4->data[i];
+							const int charsToWrite = (value > 99) ? 3 : ((value > 9) ? 2 : 1);
+							if (dest != NULL) {
+								if (written + charsToWrite <= maxChars) {
+									URI_CHAR text[4];
+									if (value > 99) {
+										text[0] = _UT('0') + (value / 100);
+										text[1] = _UT('0') + ((value % 100) / 10);
+										text[2] = _UT('0') + (value % 10);
+									} else if (value > 9)  {
+										text[0] = _UT('0') + (value / 10);
+										text[1] = _UT('0') + (value % 10);
+									} else {
+										text[0] = _UT('0') + value;
+									}
+									text[charsToWrite] = _UT('\0');
+									memcpy(dest + written, text, charsToWrite * sizeof(URI_CHAR));
+									written += charsToWrite;
+								} else {
+									dest[0] = _UT('\0');
+									if (charsWritten != NULL) {
+										*charsWritten = 0;
+									}
+									return URI_ERROR_TOSTRING_TOO_LONG;
+								}
+								if (i < 3) {
+									if (written + 1 <= maxChars) {
+										memcpy(dest + written, _UT("."),
+												1 * sizeof(URI_CHAR));
+										written += 1;
+									} else {
+										dest[0] = _UT('\0');
+										if (charsWritten != NULL) {
+											*charsWritten = 0;
+										}
+										return URI_ERROR_TOSTRING_TOO_LONG;
+									}
+								}
+							} else {
+								(*charsRequired) += charsToWrite + 1;
+							}
+						}
+					} else if (uri->hostData.ip6 != NULL) {
+						/* IPv6 */
+						int i = 0;
+						if (dest != NULL) {
+							if (written + 1 <= maxChars) {
+								memcpy(dest + written, _UT("["),
+										1 * sizeof(URI_CHAR));
+								written += 1;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+						} else {
+							(*charsRequired) += 1;
+						}
+
+						for (; i < 16; i++) {
+							const unsigned char value = uri->hostData.ip6->data[i];
+							if (dest != NULL) {
+								if (written + 2 <= maxChars) {
+									URI_CHAR text[3];
+									text[0] = URI_FUNC(HexToLetterEx)(value / 16, URI_FALSE);
+									text[1] = URI_FUNC(HexToLetterEx)(value % 16, URI_FALSE);
+									text[2] = _UT('\0');
+									memcpy(dest + written, text, 2 * sizeof(URI_CHAR));
+									written += 2;
+								} else {
+									dest[0] = _UT('\0');
+									if (charsWritten != NULL) {
+										*charsWritten = 0;
+									}
+									return URI_ERROR_TOSTRING_TOO_LONG;
+								}
+							} else {
+								(*charsRequired) += 2;
+							}
+							if (((i & 1) == 1) && (i < 15)) {
+								if (dest != NULL) {
+									if (written + 1 <= maxChars) {
+										memcpy(dest + written, _UT(":"),
+												1 * sizeof(URI_CHAR));
+										written += 1;
+									} else {
+										dest[0] = _UT('\0');
+										if (charsWritten != NULL) {
+											*charsWritten = 0;
+										}
+										return URI_ERROR_TOSTRING_TOO_LONG;
+									}
+								} else {
+									(*charsRequired) += 1;
+								}
+							}
+						}
+
+						if (dest != NULL) {
+							if (written + 1 <= maxChars) {
+								memcpy(dest + written, _UT("]"),
+										1 * sizeof(URI_CHAR));
+								written += 1;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+						} else {
+							(*charsRequired) += 1;
+						}
+					} else if (uri->hostData.ipFuture.first != NULL) {
+						/* IPvFuture */
+						const int charsToWrite = (int)(uri->hostData.ipFuture.afterLast
+								- uri->hostData.ipFuture.first);
+						if (dest != NULL) {
+							if (written + 1 <= maxChars) {
+								memcpy(dest + written, _UT("["),
+										1 * sizeof(URI_CHAR));
+								written += 1;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+
+							if (written + charsToWrite <= maxChars) {
+								memcpy(dest + written, uri->hostData.ipFuture.first, charsToWrite * sizeof(URI_CHAR));
+								written += charsToWrite;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+
+							if (written + 1 <= maxChars) {
+								memcpy(dest + written, _UT("]"),
+										1 * sizeof(URI_CHAR));
+								written += 1;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+						} else {
+							(*charsRequired) += 1 + charsToWrite + 1;
+						}
+					} else if (uri->hostText.first != NULL) {
+						/* Regname */
+						const int charsToWrite = (int)(uri->hostText.afterLast - uri->hostText.first);
+						if (dest != NULL) {
+							if (written + charsToWrite <= maxChars) {
+								memcpy(dest + written, uri->hostText.first,
+										charsToWrite * sizeof(URI_CHAR));
+								written += charsToWrite;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+						} else {
+							(*charsRequired) += charsToWrite;
+						}
+					}
+
+					/* Port */
+					if (uri->portText.first != NULL) {
+						const int charsToWrite = (int)(uri->portText.afterLast - uri->portText.first);
+						if (dest != NULL) {
+							/* Leading ':' */
+							if (written + 1 <= maxChars) {
+									memcpy(dest + written, _UT(":"),
+											1 * sizeof(URI_CHAR));
+									written += 1;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+
+							/* Port number */
+							if (written + charsToWrite <= maxChars) {
+								memcpy(dest + written, uri->portText.first,
+										charsToWrite * sizeof(URI_CHAR));
+								written += charsToWrite;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+						} else {
+							(*charsRequired) += 1 + charsToWrite;
+						}
+					}
+	/* [09/19]	endif; */
+				}
+	/* [10/19]	append path to result; */
+				/* Slash needed here? */
+				if (uri->absolutePath || ((uri->pathHead != NULL)
+						&& URI_FUNC(IsHostSet)(uri))) {
+					if (dest != NULL) {
+						if (written + 1 <= maxChars) {
+							memcpy(dest + written, _UT("/"),
+									1 * sizeof(URI_CHAR));
+							written += 1;
+						} else {
+							dest[0] = _UT('\0');
+							if (charsWritten != NULL) {
+								*charsWritten = 0;
+							}
+							return URI_ERROR_TOSTRING_TOO_LONG;
+						}
+					} else {
+						(*charsRequired) += 1;
+					}
+				}
+
+				if (uri->pathHead != NULL) {
+					URI_TYPE(PathSegment) * walker = uri->pathHead;
+					do {
+						const int charsToWrite = (int)(walker->text.afterLast - walker->text.first);
+						if (dest != NULL) {
+							if (written + charsToWrite <= maxChars) {
+								memcpy(dest + written, walker->text.first,
+										charsToWrite * sizeof(URI_CHAR));
+								written += charsToWrite;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+						} else {
+							(*charsRequired) += charsToWrite;
+						}
+
+						/* Not last segment -> append slash */
+						if (walker->next != NULL) {
+							if (dest != NULL) {
+								if (written + 1 <= maxChars) {
+									memcpy(dest + written, _UT("/"),
+											1 * sizeof(URI_CHAR));
+									written += 1;
+								} else {
+									dest[0] = _UT('\0');
+									if (charsWritten != NULL) {
+										*charsWritten = 0;
+									}
+									return URI_ERROR_TOSTRING_TOO_LONG;
+								}
+							} else {
+								(*charsRequired) += 1;
+							}
+						}
+
+						walker = walker->next;
+					} while (walker != NULL);
+				}
+	/* [11/19]	if defined(query) then */
+				if (uri->query.first != NULL) {
+	/* [12/19]		append "?" to result; */
+					if (dest != NULL) {
+						if (written + 1 <= maxChars) {
+							memcpy(dest + written, _UT("?"),
+									1 * sizeof(URI_CHAR));
+							written += 1;
+						} else {
+							dest[0] = _UT('\0');
+							if (charsWritten != NULL) {
+								*charsWritten = 0;
+							}
+							return URI_ERROR_TOSTRING_TOO_LONG;
+						}
+					} else {
+						(*charsRequired) += 1;
+					}
+	/* [13/19]		append query to result; */
+					{
+						const int charsToWrite
+								= (int)(uri->query.afterLast - uri->query.first);
+						if (dest != NULL) {
+							if (written + charsToWrite <= maxChars) {
+								memcpy(dest + written, uri->query.first,
+										charsToWrite * sizeof(URI_CHAR));
+								written += charsToWrite;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+						} else {
+							(*charsRequired) += charsToWrite;
+						}
+					}
+	/* [14/19]	endif; */
+				}
+	/* [15/19]	if defined(fragment) then */
+				if (uri->fragment.first != NULL) {
+	/* [16/19]		append "#" to result; */
+					if (dest != NULL) {
+						if (written + 1 <= maxChars) {
+							memcpy(dest + written, _UT("#"),
+									1 * sizeof(URI_CHAR));
+							written += 1;
+						} else {
+							dest[0] = _UT('\0');
+							if (charsWritten != NULL) {
+								*charsWritten = 0;
+							}
+							return URI_ERROR_TOSTRING_TOO_LONG;
+						}
+					} else {
+						(*charsRequired) += 1;
+					}
+	/* [17/19]		append fragment to result; */
+					{
+						const int charsToWrite
+								= (int)(uri->fragment.afterLast - uri->fragment.first);
+						if (dest != NULL) {
+							if (written + charsToWrite <= maxChars) {
+								memcpy(dest + written, uri->fragment.first,
+										charsToWrite * sizeof(URI_CHAR));
+								written += charsToWrite;
+							} else {
+								dest[0] = _UT('\0');
+								if (charsWritten != NULL) {
+									*charsWritten = 0;
+								}
+								return URI_ERROR_TOSTRING_TOO_LONG;
+							}
+						} else {
+							(*charsRequired) += charsToWrite;
+						}
+					}
+	/* [18/19]	endif; */
+				}
+	/* [19/19]	return result; */
+				if (dest != NULL) {
+					dest[written++] = _UT('\0');
+					if (charsWritten != NULL) {
+						*charsWritten = written;
+					}
+				}
+				return URI_SUCCESS;
+}
+
+
+
+#endif

http://git-wip-us.apache.org/repos/asf/hadoop/blob/196db0d6/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriResolve.c
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriResolve.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriResolve.c
new file mode 100644
index 0000000..cf021e7
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriResolve.c
@@ -0,0 +1,255 @@
+/*
+ * uriparser - RFC 3986 URI parsing library
+ *
+ * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
+ * Copyright (C) 2007, Sebastian Pipping <webmaster@hartwork.org>
+ * All rights reserved.
+ *
+ * Redistribution  and use in source and binary forms, with or without
+ * modification,  are permitted provided that the following conditions
+ * are met:
+ *
+ *     * Redistributions   of  source  code  must  retain  the   above
+ *       copyright  notice, this list of conditions and the  following
+ *       disclaimer.
+ *
+ *     * Redistributions  in  binary  form must  reproduce  the  above
+ *       copyright  notice, this list of conditions and the  following
+ *       disclaimer   in  the  documentation  and/or  other  materials
+ *       provided with the distribution.
+ *
+ *     * Neither  the name of the <ORGANIZATION> nor the names of  its
+ *       contributors  may  be  used to endorse  or  promote  products
+ *       derived  from  this software without specific  prior  written
+ *       permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT  NOT
+ * LIMITED  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS
+ * FOR  A  PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT  SHALL  THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL,    SPECIAL,   EXEMPLARY,   OR   CONSEQUENTIAL   DAMAGES
+ * (INCLUDING,  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT  LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE  OR  OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* What encodings are enabled? */
+#include "UriDefsConfig.h"
+#if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE))
+/* Include SELF twice */
+# define URI_PASS_ANSI 1
+# include "UriResolve.c"
+# undef URI_PASS_ANSI
+# define URI_PASS_UNICODE 1
+# include "UriResolve.c"
+# undef URI_PASS_UNICODE
+#else
+# ifdef URI_PASS_ANSI
+#  include "UriDefsAnsi.h"
+# else
+#  include "UriDefsUnicode.h"
+#  include <wchar.h>
+# endif
+
+
+
+#ifndef URI_DOXYGEN
+# include "Uri.h"
+# include "UriCommon.h"
+#endif
+
+
+
+/* Appends a relative URI to an absolute. The last path segement of
+ * the absolute URI is replaced. */
+static URI_INLINE UriBool URI_FUNC(MergePath)(URI_TYPE(Uri) * absWork,
+		const URI_TYPE(Uri) * relAppend) {
+	URI_TYPE(PathSegment) * sourceWalker;
+	URI_TYPE(PathSegment) * destPrev;
+	if (relAppend->pathHead == NULL) {
+		return URI_TRUE;
+	}
+
+	/* Replace last segment ("" if trailing slash) with first of append chain */
+	if (absWork->pathHead == NULL) {
+		URI_TYPE(PathSegment) * const dup = malloc(sizeof(URI_TYPE(PathSegment)));
+		if (dup == NULL) {
+			return URI_FALSE; /* Raises malloc error */
+		}
+		dup->next = NULL;
+		absWork->pathHead = dup;
+		absWork->pathTail = dup;
+	}
+	absWork->pathTail->text.first = relAppend->pathHead->text.first;
+	absWork->pathTail->text.afterLast = relAppend->pathHead->text.afterLast;
+
+	/* Append all the others */
+	sourceWalker = relAppend->pathHead->next;
+	if (sourceWalker == NULL) {
+		return URI_TRUE;
+	}
+	destPrev = absWork->pathTail;
+
+	for (;;) {
+		URI_TYPE(PathSegment) * const dup = malloc(sizeof(URI_TYPE(PathSegment)));
+		if (dup == NULL) {
+			destPrev->next = NULL;
+			absWork->pathTail = destPrev;
+			return URI_FALSE; /* Raises malloc error */
+		}
+		dup->text = sourceWalker->text;
+		destPrev->next = dup;
+
+		if (sourceWalker->next == NULL) {
+			absWork->pathTail = dup;
+			absWork->pathTail->next = NULL;
+			break;
+		}
+		destPrev = dup;
+		sourceWalker = sourceWalker->next;
+	}
+
+	return URI_TRUE;
+}
+
+
+
+static int URI_FUNC(AddBaseUriImpl)(URI_TYPE(Uri) * absDest,
+		const URI_TYPE(Uri) * relSource,
+		const URI_TYPE(Uri) * absBase) {
+	if (absDest == NULL) {
+		return URI_ERROR_NULL;
+	}
+	URI_FUNC(ResetUri)(absDest);
+
+	if ((relSource == NULL) || (absBase == NULL)) {
+		return URI_ERROR_NULL;
+	}
+
+	/* absBase absolute? */
+	if (absBase->scheme.first == NULL) {
+		return URI_ERROR_ADDBASE_REL_BASE;
+	}
+
+	/* [01/32]	if defined(R.scheme) then */
+				if (relSource->scheme.first != NULL) {
+	/* [02/32]		T.scheme = R.scheme; */
+					absDest->scheme = relSource->scheme;
+	/* [03/32]		T.authority = R.authority; */
+					if (!URI_FUNC(CopyAuthority)(absDest, relSource)) {
+						return URI_ERROR_MALLOC;
+					}
+	/* [04/32]		T.path = remove_dot_segments(R.path); */
+					if (!URI_FUNC(CopyPath)(absDest, relSource)) {
+						return URI_ERROR_MALLOC;
+					}
+					if (!URI_FUNC(RemoveDotSegmentsAbsolute)(absDest)) {
+						return URI_ERROR_MALLOC;
+					}
+	/* [05/32]		T.query = R.query; */
+					absDest->query = relSource->query;
+	/* [06/32]	else */
+				} else {
+	/* [07/32]		if defined(R.authority) then */
+					if (URI_FUNC(IsHostSet)(relSource)) {
+	/* [08/32]			T.authority = R.authority; */
+						if (!URI_FUNC(CopyAuthority)(absDest, relSource)) {
+							return URI_ERROR_MALLOC;
+						}
+	/* [09/32]			T.path = remove_dot_segments(R.path); */
+						if (!URI_FUNC(CopyPath)(absDest, relSource)) {
+							return URI_ERROR_MALLOC;
+						}
+						if (!URI_FUNC(RemoveDotSegmentsAbsolute)(absDest)) {
+							return URI_ERROR_MALLOC;
+						}
+	/* [10/32]			T.query = R.query; */
+						absDest->query = relSource->query;
+	/* [11/32]		else */
+					} else {
+	/* [28/32]			T.authority = Base.authority; */
+						if (!URI_FUNC(CopyAuthority)(absDest, absBase)) {
+							return URI_ERROR_MALLOC;
+						}
+	/* [12/32]			if (R.path == "") then */
+						if (relSource->pathHead == NULL) {
+	/* [13/32]				T.path = Base.path; */
+							if (!URI_FUNC(CopyPath)(absDest, absBase)) {
+								return URI_ERROR_MALLOC;
+							}
+	/* [14/32]				if defined(R.query) then */
+							if (relSource->query.first != NULL) {
+	/* [15/32]					T.query = R.query; */
+								absDest->query = relSource->query;
+	/* [16/32]				else */
+							} else {
+	/* [17/32]					T.query = Base.query; */
+								absDest->query = absBase->query;
+	/* [18/32]				endif; */
+							}
+	/* [19/32]			else */
+						} else {
+	/* [20/32]				if (R.path starts-with "/") then */
+							if (relSource->absolutePath) {
+	/* [21/32]					T.path = remove_dot_segments(R.path); */
+								if (!URI_FUNC(CopyPath)(absDest, relSource)) {
+									return URI_ERROR_MALLOC;
+								}
+								if (!URI_FUNC(RemoveDotSegmentsAbsolute)(absDest)) {
+									return URI_ERROR_MALLOC;
+								}
+	/* [22/32]				else */
+							} else {
+	/* [23/32]					T.path = merge(Base.path, R.path); */
+								if (!URI_FUNC(CopyPath)(absDest, absBase)) {
+									return URI_ERROR_MALLOC;
+								}
+								if (!URI_FUNC(MergePath)(absDest, relSource)) {
+									return URI_ERROR_MALLOC;
+								}
+	/* [24/32]					T.path = remove_dot_segments(T.path); */
+								if (!URI_FUNC(RemoveDotSegmentsAbsolute)(absDest)) {
+									return URI_ERROR_MALLOC;
+								}
+
+								if (!URI_FUNC(FixAmbiguity)(absDest)) {
+									return URI_ERROR_MALLOC;
+								}
+	/* [25/32]				endif; */
+							}
+	/* [26/32]				T.query = R.query; */
+							absDest->query = relSource->query;
+	/* [27/32]			endif; */
+						}
+						URI_FUNC(FixEmptyTrailSegment)(absDest);
+	/* [29/32]		endif; */
+					}
+	/* [30/32]		T.scheme = Base.scheme; */
+					absDest->scheme = absBase->scheme;
+	/* [31/32]	endif; */
+				}
+	/* [32/32]	T.fragment = R.fragment; */
+				absDest->fragment = relSource->fragment;
+
+	return URI_SUCCESS;
+
+}
+
+
+
+int URI_FUNC(AddBaseUri)(URI_TYPE(Uri) * absDest,
+		const URI_TYPE(Uri) * relSource, const URI_TYPE(Uri) * absBase) {
+	const int res = URI_FUNC(AddBaseUriImpl)(absDest, relSource, absBase);
+	if ((res != URI_SUCCESS) && (absDest != NULL)) {
+		URI_FUNC(FreeUriMembers)(absDest);
+	}
+	return res;
+}
+
+
+
+#endif

http://git-wip-us.apache.org/repos/asf/hadoop/blob/196db0d6/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriShorten.c
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriShorten.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriShorten.c
new file mode 100644
index 0000000..cb22ada
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser/UriShorten.c
@@ -0,0 +1,316 @@
+/*
+ * uriparser - RFC 3986 URI parsing library
+ *
+ * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
+ * Copyright (C) 2007, Sebastian Pipping <webmaster@hartwork.org>
+ * All rights reserved.
+ *
+ * Redistribution  and use in source and binary forms, with or without
+ * modification,  are permitted provided that the following conditions
+ * are met:
+ *
+ *     * Redistributions   of  source  code  must  retain  the   above
+ *       copyright  notice, this list of conditions and the  following
+ *       disclaimer.
+ *
+ *     * Redistributions  in  binary  form must  reproduce  the  above
+ *       copyright  notice, this list of conditions and the  following
+ *       disclaimer   in  the  documentation  and/or  other  materials
+ *       provided with the distribution.
+ *
+ *     * Neither  the name of the <ORGANIZATION> nor the names of  its
+ *       contributors  may  be  used to endorse  or  promote  products
+ *       derived  from  this software without specific  prior  written
+ *       permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT  NOT
+ * LIMITED  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS
+ * FOR  A  PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT  SHALL  THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL,    SPECIAL,   EXEMPLARY,   OR   CONSEQUENTIAL   DAMAGES
+ * (INCLUDING,  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT  LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE  OR  OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* What encodings are enabled? */
+#include "UriDefsConfig.h"
+#if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE))
+/* Include SELF twice */
+# define URI_PASS_ANSI 1
+# include "UriShorten.c"
+# undef URI_PASS_ANSI
+# define URI_PASS_UNICODE 1
+# include "UriShorten.c"
+# undef URI_PASS_UNICODE
+#else
+# ifdef URI_PASS_ANSI
+#  include "UriDefsAnsi.h"
+# else
+#  include "UriDefsUnicode.h"
+#  include <wchar.h>
+# endif
+
+
+
+#ifndef URI_DOXYGEN
+# include "Uri.h"
+# include "UriCommon.h"
+#endif
+
+
+
+static URI_INLINE UriBool URI_FUNC(AppendSegment)(URI_TYPE(Uri) * uri,
+		const URI_CHAR * first, const URI_CHAR * afterLast) {
+	/* Create segment */
+	URI_TYPE(PathSegment) * segment = malloc(1 * sizeof(URI_TYPE(PathSegment)));
+	if (segment == NULL) {
+		return URI_FALSE; /* Raises malloc error */
+	}
+	segment->next = NULL;
+	segment->text.first = first;
+	segment->text.afterLast = afterLast;
+
+	/* Put into chain */
+	if (uri->pathTail == NULL) {
+		uri->pathHead = segment;
+	} else {
+		uri->pathTail->next = segment;
+	}
+	uri->pathTail = segment;
+
+	return URI_TRUE;
+}
+
+
+
+static URI_INLINE UriBool URI_FUNC(EqualsAuthority)(const URI_TYPE(Uri) * first,
+		const URI_TYPE(Uri) * second) {
+	/* IPv4 */
+	if (first->hostData.ip4 != NULL) {
+		return ((second->hostData.ip4 != NULL)
+				&& !memcmp(first->hostData.ip4->data,
+					second->hostData.ip4->data, 4)) ? URI_TRUE : URI_FALSE;
+	}
+
+	/* IPv6 */
+	if (first->hostData.ip6 != NULL) {
+		return ((second->hostData.ip6 != NULL)
+				&& !memcmp(first->hostData.ip6->data,
+					second->hostData.ip6->data, 16)) ? URI_TRUE : URI_FALSE;
+	}
+
+	/* IPvFuture */
+	if (first->hostData.ipFuture.first != NULL) {
+		return ((second->hostData.ipFuture.first != NULL)
+				&& !URI_STRNCMP(first->hostData.ipFuture.first,
+					second->hostData.ipFuture.first,
+					first->hostData.ipFuture.afterLast
+					- first->hostData.ipFuture.first))
+						? URI_TRUE : URI_FALSE;
+	}
+
+	if (first->hostText.first != NULL) {
+		return ((second->hostText.first != NULL)
+				&& !URI_STRNCMP(first->hostText.first,
+					second->hostText.first,
+					first->hostText.afterLast
+					- first->hostText.first)) ? URI_TRUE : URI_FALSE;
+	}
+
+	return (second->hostText.first == NULL);
+}
+
+
+
+int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
+		const URI_TYPE(Uri) * absSource,
+		const URI_TYPE(Uri) * absBase,
+		UriBool domainRootMode) {
+	if (dest == NULL) {
+		return URI_ERROR_NULL;
+	}
+	URI_FUNC(ResetUri)(dest);
+
+	if ((absSource == NULL) || (absBase == NULL)) {
+		return URI_ERROR_NULL;
+	}
+
+	/* absBase absolute? */
+	if (absBase->scheme.first == NULL) {
+		return URI_ERROR_REMOVEBASE_REL_BASE;
+	}
+
+	/* absSource absolute? */
+	if (absSource->scheme.first == NULL) {
+		return URI_ERROR_REMOVEBASE_REL_SOURCE;
+	}
+
+	/* [01/50]	if (A.scheme != Base.scheme) then */
+				if (URI_STRNCMP(absSource->scheme.first, absBase->scheme.first,
+						absSource->scheme.afterLast - absSource->scheme.first)) {
+	/* [02/50]	   T.scheme    = A.scheme; */
+					dest->scheme = absSource->scheme;
+	/* [03/50]	   T.authority = A.authority; */
+					if (!URI_FUNC(CopyAuthority)(dest, absSource)) {
+						return URI_ERROR_MALLOC;
+					}
+	/* [04/50]	   T.path      = A.path; */
+					if (!URI_FUNC(CopyPath)(dest, absSource)) {
+						return URI_ERROR_MALLOC;
+					}
+	/* [05/50]	else */
+				} else {
+	/* [06/50]	   undef(T.scheme); */
+					/* NOOP */
+	/* [07/50]	   if (A.authority != Base.authority) then */
+					if (!URI_FUNC(EqualsAuthority)(absSource, absBase)) {
+	/* [08/50]	      T.authority = A.authority; */
+						if (!URI_FUNC(CopyAuthority)(dest, absSource)) {
+							return URI_ERROR_MALLOC;
+						}
+	/* [09/50]	      T.path      = A.path; */
+						if (!URI_FUNC(CopyPath)(dest, absSource)) {
+							return URI_ERROR_MALLOC;
+						}
+	/* [10/50]	   else */
+					} else {
+	/* [11/50]	      if domainRootMode then */
+						if (domainRootMode == URI_TRUE) {
+	/* [12/50]	         undef(T.authority); */
+							/* NOOP */
+	/* [13/50]	         if (first(A.path) == "") then */
+							/* GROUPED */
+	/* [14/50]	            T.path   = "/." + A.path; */
+								/* GROUPED */
+	/* [15/50]	         else */
+								/* GROUPED */
+	/* [16/50]	            T.path   = A.path; */
+								/* GROUPED */
+	/* [17/50]	         endif; */
+							if (!URI_FUNC(CopyPath)(dest, absSource)) {
+								return URI_ERROR_MALLOC;
+							}
+							dest->absolutePath = URI_TRUE;
+
+							if (!URI_FUNC(FixAmbiguity)(dest)) {
+								return URI_ERROR_MALLOC;
+							}
+	/* [18/50]	      else */
+						} else {
+							const URI_TYPE(PathSegment) * sourceSeg = absSource->pathHead;
+							const URI_TYPE(PathSegment) * baseSeg = absBase->pathHead;
+	/* [19/50]	         bool pathNaked = true; */
+							UriBool pathNaked = URI_TRUE;
+	/* [20/50]	         undef(last(Base.path)); */
+							/* NOOP */
+	/* [21/50]	         T.path = ""; */
+							dest->absolutePath = URI_FALSE;
+	/* [22/50]	         while (first(A.path) == first(Base.path)) do */
+							while ((sourceSeg != NULL) && (baseSeg != NULL)
+									&& !URI_STRNCMP(sourceSeg->text.first, baseSeg->text.first,
+									sourceSeg->text.afterLast - sourceSeg->text.first)
+									&& !((sourceSeg->text.first == sourceSeg->text.afterLast)
+										&& ((sourceSeg->next == NULL) != (baseSeg->next == NULL)))) {
+	/* [23/50]	            A.path++; */
+								sourceSeg = sourceSeg->next;
+	/* [24/50]	            Base.path++; */
+								baseSeg = baseSeg->next;
+	/* [25/50]	         endwhile; */
+							}
+	/* [26/50]	         while defined(first(Base.path)) do */
+							while ((baseSeg != NULL) && (baseSeg->next != NULL)) {
+	/* [27/50]	            Base.path++; */
+								baseSeg = baseSeg->next;
+	/* [28/50]	            T.path += "../"; */
+								if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstParent),
+										URI_FUNC(ConstParent) + 2)) {
+									return URI_ERROR_MALLOC;
+								}
+	/* [29/50]	            pathNaked = false; */
+								pathNaked = URI_FALSE;
+	/* [30/50]	         endwhile; */
+							}
+	/* [31/50]	         while defined(first(A.path)) do */
+							while (sourceSeg != NULL) {
+	/* [32/50]	            if pathNaked then */
+								if (pathNaked == URI_TRUE) {
+	/* [33/50]	               if (first(A.path) contains ":") then */
+									UriBool containsColon = URI_FALSE;
+									const URI_CHAR * ch = sourceSeg->text.first;
+									for (; ch < sourceSeg->text.afterLast; ch++) {
+										if (*ch == _UT(':')) {
+											containsColon = URI_TRUE;
+											break;
+										}
+									}
+
+									if (containsColon) {
+	/* [34/50]	                  T.path += "./"; */
+										if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstPwd),
+												URI_FUNC(ConstPwd) + 1)) {
+											return URI_ERROR_MALLOC;
+										}
+	/* [35/50]	               elseif (first(A.path) == "") then */
+									} else if (sourceSeg->text.first == sourceSeg->text.afterLast) {
+	/* [36/50]	                  T.path += "/."; */
+										if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstPwd),
+												URI_FUNC(ConstPwd) + 1)) {
+											return URI_ERROR_MALLOC;
+										}
+	/* [37/50]	               endif; */
+									}
+	/* [38/50]	            endif; */
+								}
+	/* [39/50]	            T.path += first(A.path); */
+								if (!URI_FUNC(AppendSegment)(dest, sourceSeg->text.first,
+										sourceSeg->text.afterLast)) {
+									return URI_ERROR_MALLOC;
+								}
+	/* [40/50]	            pathNaked = false; */
+								pathNaked = URI_FALSE;
+	/* [41/50]	            A.path++; */
+								sourceSeg = sourceSeg->next;
+	/* [42/50]	            if defined(first(A.path)) then */
+								/* NOOP */
+	/* [43/50]	               T.path += + "/"; */
+								/* NOOP */
+	/* [44/50]	            endif; */
+								/* NOOP */
+	/* [45/50]	         endwhile; */
+							}
+	/* [46/50]	      endif; */
+						}
+	/* [47/50]	   endif; */
+					}
+	/* [48/50]	endif; */
+				}
+	/* [49/50]	T.query     = A.query; */
+				dest->query = absSource->query;
+	/* [50/50]	T.fragment  = A.fragment; */
+				dest->fragment = absSource->fragment;
+
+	return URI_SUCCESS;
+}
+
+
+
+int URI_FUNC(RemoveBaseUri)(URI_TYPE(Uri) * dest,
+		const URI_TYPE(Uri) * absSource,
+		const URI_TYPE(Uri) * absBase,
+		UriBool domainRootMode) {
+	const int res = URI_FUNC(RemoveBaseUriImpl)(dest, absSource,
+			absBase, domainRootMode);
+	if ((res != URI_SUCCESS) && (dest != NULL)) {
+		URI_FUNC(FreeUriMembers)(dest);
+	}
+	return res;
+}
+
+
+
+#endif

http://git-wip-us.apache.org/repos/asf/hadoop/blob/196db0d6/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser2.c
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser2.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser2.c
new file mode 100644
index 0000000..ab6209c
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser2.c
@@ -0,0 +1,273 @@
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "uriparser/Uri.h"
+#include "uriparser2.h"
+
+/* copy n bytes from src to dst and add a nul byte. dst must be large enough to hold n + 1 bytes. */
+static char *memcpyz(char *dst, const char *src, int n) {
+	memcpy(dst, src, n);
+	dst[n] = '\0';
+	return dst;
+}
+
+/* returns the number of chars required to store the range as a string, including the nul byte */
+static int range_size(const UriTextRangeA *r) {
+	if (r->first && r->first != r->afterLast) {
+		return 1 + (r->afterLast - r->first);
+	}
+	return 0;
+}
+
+/* returns the number of chars required to store the path, including the nul byte */
+static int path_size(const UriPathSegmentA *ps) {
+	if (ps) {
+		/* +1 for the nul byte; the extra byte from range_size() is used for the leading slash */
+		int size = 1;
+		for (; ps != 0; ps = ps->next) {
+			size += range_size(&ps->text);
+		}
+		return size;
+	}
+	return 0;
+}
+
+static int uri_size(const UriUriA *uu) {
+	return range_size(&uu->scheme)
+		+ range_size(&uu->userInfo) + 1	/* userinfo will be split on : */
+		+ range_size(&uu->hostText)
+		+ path_size(uu->pathHead)
+		+ range_size(&uu->query)
+		+ range_size(&uu->fragment);
+}
+
+static const char *copy_range(const UriTextRangeA *r, char **buffer) {
+	const int size = r->afterLast - r->first;
+	if (size) {
+		const char *s = *buffer;
+		memcpyz(*buffer, r->first, size);
+		*buffer += size + 1;
+		return s;
+	}
+	return 0;
+}
+
+static const char *copy_path(const UriPathSegmentA *ps, char **buffer) {
+	const char *s = *buffer;
+
+	for (; ps != 0; ps = ps->next) {
+		**buffer = '/'; (*buffer)++;
+		copy_range(&ps->text, buffer);
+		if (ps->next) {
+			/* chop off trailing null, we'll append at least one more path segment */
+			(*buffer)--;
+		}
+	}
+
+	return s;
+}
+
+static int parse_int(const char *first, const char *after_last) {
+	const int size = after_last - first;
+	if (size) {
+		char buffer[size + 1];
+		memcpyz(buffer, first, size);
+		return atoi(buffer);
+	}
+	return 0;
+}
+
+static void parse_user_info(URI *uri, const UriTextRangeA *r, char **buffer) {
+	uri->user = uri->pass = 0;
+
+	const int size = r->afterLast - r->first;
+	if (size) {
+		char *colon = memchr(r->first, ':', size);
+
+		const int user_size = (colon ? colon : r->afterLast) - r->first;
+		const int pass_size = r->afterLast - (colon ? colon + 1 : r->afterLast);
+
+		if (user_size) {
+			uri->user = memcpyz(*buffer, r->first, user_size);
+			*buffer += user_size + 1;
+		}
+		if (pass_size) {
+			uri->pass = memcpyz(*buffer, colon + 1, pass_size);
+			*buffer += pass_size + 1;
+		}
+	}
+}
+
+static void init_uri(const UriUriA *uu, URI *uri, char *buffer) {
+	uri->scheme = copy_range(&uu->scheme, &buffer);
+	uri->user = 0;
+	uri->pass = 0;
+	uri->host = copy_range(&uu->hostText, &buffer);
+	uri->port = parse_int(uu->portText.first, uu->portText.afterLast);
+	uri->path = copy_path(uu->pathHead, &buffer);
+	uri->query = copy_range(&uu->query, &buffer);
+	uri->fragment = copy_range(&uu->fragment, &buffer);
+	parse_user_info(uri, &uu->userInfo, &buffer);
+}
+
+/* this function saves the URI components after the URI object itself, so it can be released with a single call to free() */
+URI *uri_parse(const char *input) {
+	UriParserStateA state;
+	UriUriA uu;
+	URI *uri;
+
+	state.uri = &uu;
+	if (URI_SUCCESS == uriParseUriA(&state, input)) {
+		uri = calloc(1, sizeof(*uri) + uri_size(&uu));
+		if (uri) {
+			init_uri(&uu, uri, (char *) (uri + 1));
+		} else {
+			/* work around non-conformant malloc() implementations */
+			errno = ENOMEM;
+		}
+	} else {
+		uri = 0;
+	}
+
+	int saved_errno = errno;
+	uriFreeUriMembersA(&uu);
+	errno = saved_errno;
+
+	return uri;
+}
+
+/* this is a helper function for the C++ constructor that saves the URI components to a separately malloc()'ed buffer */
+void *uri_parse2(const char *input, URI *uri) {
+	UriParserStateA state;
+	char *buffer;
+	UriUriA uu;
+
+	state.uri = &uu;
+	if (URI_SUCCESS == uriParseUriA(&state, input)) {
+		buffer = malloc(uri_size(&uu));
+		if (buffer) {
+			init_uri(&uu, uri, buffer);
+		} else {
+			/* work around non-conformant malloc() implementations */
+			errno = ENOMEM;
+		}
+	} else {
+		buffer = 0;
+	}
+
+	int saved_errno = errno;
+	uriFreeUriMembersA(&uu);
+	errno = saved_errno;
+
+	return buffer;
+}
+
+static char *append(char *dst, const char *src) {
+	const int size = strlen(src);
+	memcpy(dst, src, size);
+	return dst + size;
+}
+
+static int power_of_10(int n) {
+	int i;
+	for (i = 0; n > 0; i++, n /= 10);
+	return i;
+}
+
+char *uri_build(const URI *uri) {
+	int size = 0;
+
+	if (uri->scheme) {
+		size += strlen(uri->scheme) + 3;	/* "://" */
+	}
+	if (uri->user) {
+		size += strlen(uri->user) + 1;		/* ":" or "@" */
+	}
+	if (uri->pass) {
+		size += strlen(uri->pass) + 1;		/* "@" */
+	}
+	if (uri->host) {
+		size += strlen(uri->host);
+	}
+	if (uri->port) {
+		size += 1 + power_of_10(uri->port);	/* ":" port */
+	}
+	if (uri->path) {
+		size += strlen(uri->path);
+	}
+	if (uri->query) {
+		size += 1 + strlen(uri->query);		/* "?" query */
+	}
+	if (uri->fragment) {
+		size += 1 + strlen(uri->fragment);	/* "#" fragment */
+	}
+
+	char *s = malloc(size + 1);
+	if (s) {
+		char *p = s;
+		if (uri->scheme) {
+			p = append(p, uri->scheme);
+			*p++ = ':';
+			*p++ = '/';
+			*p++ = '/';
+		}
+		if (uri->user) {
+			p = append(p, uri->user);
+		}
+		if (uri->pass) {
+			*p++ = ':';
+			p = append(p, uri->pass);
+		}
+		if (uri->user || uri->pass) {
+			*p++ = '@';
+		}
+		if (uri->host) {
+			p = append(p, uri->host);
+		}
+		if (uri->port) {
+			p += sprintf(p, ":%d", uri->port);
+		}
+		if (uri->path) {
+			p = append(p, uri->path);
+		}
+		if (uri->query) {
+			*p++ = '?';
+			p = append(p, uri->query);
+		}
+		if (uri->fragment) {
+			*p++ = '#';
+			p = append(p, uri->fragment);
+		}
+		*p = '\0';
+	}
+
+	return s;
+}
+
+/* NULL-safe string comparison. a < b if a is NULL and b is not (and vice versa). */
+#define COMPARE(a, b)			\
+	if (a && b) {			\
+		int n = strcmp(a, b);	\
+		if (n) return n;	\
+	} else if (a || b) {		\
+		return a ? 1 : -1;	\
+	}
+
+int uri_compare(const URI *a, const URI *b) {
+	COMPARE(a->scheme, b->scheme);
+	COMPARE(a->host, b->host);
+
+	if (a->port != b->port) {
+		return a->port > b->port ? 1 : -1;
+	}
+
+	COMPARE(a->path, b->path);
+	COMPARE(a->query, b->query);
+	COMPARE(a->fragment, b->fragment);
+
+	COMPARE(a->user, b->user);
+	COMPARE(a->pass, b->pass);
+
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/196db0d6/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser2.h
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser2.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser2.h
new file mode 100644
index 0000000..252c2f5
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/uriparser2/uriparser2/uriparser2.h
@@ -0,0 +1,101 @@
+#ifndef URIPARSER2_H_
+#define URIPARSER2_H_
+
+#ifdef __cplusplus
+#include <string>
+#endif
+
+/**
+ * URI object. After the call to uri_parse() fields will be NULL (0 for the port) if their component was absent in the input string.
+ */
+typedef struct URI {
+	const char *scheme;
+	const char *user;
+	const char *pass;
+	const char *host;
+	unsigned short port;
+	const char *path;
+	const char *query;
+	const char *fragment;
+#ifdef __cplusplus
+	const void *const reserved;
+
+	URI(const char *uri = 0);
+	~URI();
+
+	bool operator<(const URI& uri) const;
+	bool operator>(const URI& uri) const;
+	bool operator<=(const URI& uri) const;
+	bool operator>=(const URI& uri) const;
+	bool operator==(const URI& uri) const;
+	bool operator!=(const URI& uri) const;
+
+	std::string to_string() const;
+#endif
+} URI;
+
+#ifdef __cplusplus
+
+#include <ostream>
+#include <cstdlib>
+
+extern "C" void *uri_parse2(const char *uri, URI *target);
+extern "C" char *uri_build(const URI *uri);
+extern "C" int uri_compare(const URI *a, const URI *b);
+
+inline URI::URI(const char* uri): reserved(uri ? uri_parse2(uri, this) : 0) {
+}
+
+inline URI::~URI() {
+	free((void *) reserved);
+}
+
+inline std::string URI::to_string() const {
+	char *s = uri_build(this);	/* FIXME handle NULL return value (ENOMEM) */
+	std::string rv(s);
+	free(s);
+	return rv;
+}
+
+inline bool URI::operator<(const URI& uri) const { return uri_compare(this, &uri) < 0; }
+inline bool URI::operator>(const URI& uri) const { return uri_compare(this, &uri) > 0; }
+inline bool URI::operator<=(const URI& uri) const { return uri_compare(this, &uri) <= 0; }
+inline bool URI::operator>=(const URI& uri) const { return uri_compare(this, &uri) >= 0; }
+inline bool URI::operator==(const URI& uri) const { return uri_compare(this, &uri) == 0; }
+inline bool URI::operator!=(const URI& uri) const { return uri_compare(this, &uri) != 0; }
+
+static inline std::ostream& operator<<(std::ostream& os, const URI& uri) {
+	return os << uri.to_string();
+}
+
+#else	/* defined(__cplusplus) */
+
+/**
+ * Parse URI into its components.
+ *
+ * @param uri The URI to parse.
+ * @return URI object. The caller is responsible for freeing this object. NULL is returned on parse error or out-of-memory conditions (in the latter case errno=ENOMEM).
+ */
+URI *uri_parse(const char *uri);
+
+/**
+ * Create string representation of URI object.
+ *
+ * @param uri URI object.
+ * @return URI as a string. The caller is responsible for freeing this object. NULL is returned on out-of-memory conditions (errno=ENOMEM).
+ */
+char *uri_build(const URI *uri);
+
+/**
+ * Compare two URI objects. Follows the strcmp() contract. The order in which components are compared is as follows: scheme, host, port, path, query, fragment, user, pass.
+ * NULL components are always smaller than their non-NULL counterparts. That is, a < b if a->scheme == NULL and b->scheme != NULL.
+ *
+ * @param a First URI object.
+ * @param b Second URI object.
+ * @return -1 if a < b, 0 if a == b, 1 if a > b.
+ */
+int uri_compare(const URI *a, const URI *b);
+
+#endif	/* __cplusplus */
+
+#endif	/* uriparser2.h */


Mime
View raw message